<html><head><link href="../../../css-stylesheets/elucidator/program.css" rel="stylesheet" title="program" type="text/css" /> <title>Source file</title></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000"><font size="2"><pre><span class="comment">; =&gt;man/general.sdoc</span><br />
<div class="schemedoc-abstract-comment">;;;; .title Reference Manual of the General LAML library
;;;; .schemedoc-dependencies  "man/color" "man/time" "compatibility/man/mzscheme-compat"
;;;; This is a library of common and generally useful Scheme functions, which are used in other LAML libraries,
;;;; in LAML styles, and in LAML tools. Far the majority of the functions can also be used outside LAML. </div>
<span class="comment">; The LAML library and programs written by Kurt Normark, Aalborg University, Denmark.
; Copyright (C) 1999-2005  Kurt Normark, normark@s.auc.dk.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span><br />
<span class="comment">; ---------------------------------------------------------------------------------------------------</span><br />
<div class="schemedoc-section-comment">;;; Optional parameter handling.
;;; Given the function &lt;kbd&gt;(lambda (r1 r2 . optional-parameters) ...)&lt;/kbd&gt; the function
;;; &lt;kbd&gt;optional-parameter&lt;/kbd&gt; (see below) is able to extract optional parameter number n. Non-used optional parameter can
;;; either be passed as the #f value (false in Scheme) or not passed at all. 
;;; .section-id optional-parameter-section</div>
<a name="optional-parameter"></a><div class="schemedoc-definition-comment">;; Return element n of optional-parameter-list. The first element is number 1.
;; In Scheme the optional parameters are captured as a list after the required parameters: &lt;kbd&gt;(define f (x y . optional-parameter-list) ...)&lt;/kbd&gt;.
;; Please notice that if you pass optional parameter number i, the optional parameters 1, 2, ..., i-1 must be passed explicitly.
;; If you explicitly pass the symbol non-passed-value, this function will always return the default value, default-value.
;; (This means, of course, that you cannot use the symbol non-passed-value as an 'ordinary value' in your program).
;; If no optional third parameter - default-value - is given to the function optional-parameter the value #f serves as the default default-value.
;; .form (optional-parameter n optional-parameter-list [default-value])
;; .pre-condition optional-parameter-list is a proper list.</div><a name="optional-parameter"></a><span><a href="../general.html#optional-parameter"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(optional-parameter n optional-parameter-list . optional-default-value)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">optional-default-value-1</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> optional-default-value) #f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> optional-default-value))))  <span class="comment">; the old fashioned way of handling it...</span><br />   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> optional-parameter-list))
       optional-default-value-1
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">candidate-value</span>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX337" title="R5RS Scheme form">list-ref</a> optional-parameter-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> candidate-value 'non-passed-value)
             optional-default-value-1
             candidate-value))))) 


<div class="schemedoc-section-comment">;;; .section-id selection-generation
;;; List selection functions and their generators. 
;;; As an alternative to using car, cadr etc. we provide for generation of more general list selector functions.</div>

<a name="make-selector-function"></a><div class="schemedoc-definition-comment">;; Returns a function, which selects element number n in a list.
;; The second parameter, which is optional, is used for error message purposes.
;; In general, this parameter should be a string corresponding to the name of the selector function.
;; If the second parameter is given, we check whether the list is long enough for selection.
;; If not, we give a decent error message. We recommend use of the second parameter in order to
;; avoid meaningless error messages.
;; The first element is number 1.
;; (make-selector-function 1) corresponds to car, (make-selector-function 2) corresponds to cadr, etc.
;; .form (make-selector-function n [selector-name])</div><a name="make-selector-function"></a><span><a href="../general.html#make-selector-function"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-selector-function n . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">selector-name</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list #f)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> selector-name
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span>) 
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX331" title="R5RS Scheme form">list?</a> lst)
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
		   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
		       (<a class="applied-name" href="general-1.html#display-error" title="general">display-error</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The selector function " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> selector-name) ": " 
						     "The list "  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst) " is is too short for selection. "
						     "It must have at least " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n) " elements."
						     ))
		       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX337" title="R5RS Scheme form">list-ref</a> lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))))
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#display-error" title="general">display-error</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The selector function " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> selector-name) ": " 
						   "The parameter  "  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst) "  is supposed to be a list. "
                                                   "In addition, it must have at least "
				                    (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n) " elements."
						     )))))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX337" title="R5RS Scheme form">list-ref</a> lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))))

<a name="make-mutator-function"></a><div class="schemedoc-definition-comment">;; Make and return a mutator function which mutates element number n in a list.
;; The returned function takes a list and a new value as arguments.
;; This function takes one optional parameter, which is the name of the mutator.
;; .form (make-mutator-function n [mutator-name])
;; .parameter n The position in the last to be mutated. The first element counts as number 1.
;; .parameter mutator-name The name of the mutator function. Used only for error message purposes.
;; .returns A function of two parameters (lambda (lst new-value) ...) that mutates element n of lst to new-value.</div><a name="make-mutator-function"></a><span><a href="../general.html#make-mutator-function"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-mutator-function n . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">mutator-name</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> mutator-name
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span> <span class="local-name-binding">new-value</span>) 
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
                (<a class="applied-name" href="general-1.html#display-error" title="general">display-error</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The mutator function " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> mutator-name) ": " 
                                 "The list "  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst) " is is too short for mutator. "
                                 "It must have at least " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n) " elements."
                               ))
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">cons-pair</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX323" title="R5RS Scheme form">set-car!</a> cons-pair new-value)))))
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span> <span class="local-name-binding">new-value</span>) 
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
                (<a class="applied-name" href="general-1.html#display-error" title="general">display-error</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Error in mutator:"
                                 "The list "  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst) " is is too short for mutator. "
                                 "It must have at least " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n) " elements."))
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">cons-pair</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX323" title="R5RS Scheme form">set-car!</a> cons-pair new-value))))))))


<a name="first"></a><div class="schemedoc-definition-comment">;; Return the first element of a list
;; .form (first lst)</div><a name="first"></a><span><a href="../general.html#first"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">first</span> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a>)

<a name="second"></a><div class="schemedoc-definition-comment">;; Return the second element of a list
;; .form (second lst)</div><a name="second"></a><span><a href="../general.html#second"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">second</span> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a>)

<a name="third"></a><div class="schemedoc-definition-comment">;; Return the third element of a list
;; .form (third lst)</div><a name="third"></a><span><a href="../general.html#third"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">third</span> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">caddr</a>)

<a name="fourth"></a><div class="schemedoc-definition-comment">;; Return the fourth element of a list
;; .form (fourth lst)</div><a name="fourth"></a><span><a href="../general.html#fourth"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">fourth</span> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadddr</a>)

<a name="fifth"></a><div class="schemedoc-definition-comment">;; Return the fifth element of a list
;; .form (fifth lst)
;; .returns The fifth element of the list</div><a name="fifth"></a><span><a href="../general.html#fifth"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">fifth</span> (<a class="applied-name" href="general-1.html#make-selector-function" title="general">make-selector-function</a> 5))

<a name="sixth"></a><div class="schemedoc-definition-comment">;; Return the sixth element of a list
;; .form (sixth lst)</div><a name="sixth"></a><span><a href="../general.html#sixth"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">sixth</span> (<a class="applied-name" href="general-1.html#make-selector-function" title="general">make-selector-function</a> 6))

<a name="seventh"></a><div class="schemedoc-definition-comment">;; Return the seventh element of a list
;; .form (seventh lst)</div><a name="seventh"></a><span><a href="../general.html#seventh"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">seventh</span> (<a class="applied-name" href="general-1.html#make-selector-function" title="general">make-selector-function</a> 7))

<a name="eighth"></a><div class="schemedoc-definition-comment">;; Return the eighth element of a list
;; .form (eighth lst)</div><a name="eighth"></a><span><a href="../general.html#eighth"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">eighth</span> (<a class="applied-name" href="general-1.html#make-selector-function" title="general">make-selector-function</a> 8))

<a name="nineth"></a><div class="schemedoc-definition-comment">;; Return the nineth element of a list
;; .form (nineth lst)</div><a name="nineth"></a><span><a href="../general.html#nineth"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">nineth</span> (<a class="applied-name" href="general-1.html#make-selector-function" title="general">make-selector-function</a> 9))


<div class="schemedoc-section-comment">;;; Association and property list functions. 
;;; Here follows a number of functions which work on alists, or make alists. Also a number of property list functions are provided.</div>
<a name="extend-a-list"></a><div class="schemedoc-definition-comment">;; Add a key-value pair to a-list. Like acons in some systems.</div><a name="extend-a-list"></a><span><a href="../general.html#extend-a-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(extend-a-list key value a-list)</span>
 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="applied-name" href="general-1.html#as-symbol" title="general">as-symbol</a> key) value) a-list))

<a name="get"></a><div class="schemedoc-definition-comment">;; Return a value from an alist which corresponds to key.
;; In case the key does not exist in the alist, a fatal error will occur.
;; .parameter key is a symbol.
;; .parameter a-list an association list with symbols as keys.
;; .returns the first value of key in a-list.
;; .misc Uses the function assq (based on eq? for key comparions) internally.
;; .internal-references "similar function" "defaulted-get"</div><a name="get"></a><span><a href="../general.html#get"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(get key a-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX341" title="R5RS Scheme form">assq</a> key a-list)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> res) 
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> res)
        (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Get: Cannot find " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> key) " in " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> a-list))))))

<a name="defaulted-get"></a><div class="schemedoc-definition-comment">;; Return the value of key in alist (by means of cdr of assq). If no association is found return default.
;; .internal-references "similar function" "get"</div><a name="defaulted-get"></a><span><a href="../general.html#defaulted-get"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(defaulted-get key alist default)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX341" title="R5RS Scheme form">assq</a> key alist)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> res
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> res)
       default)))


<a name="get-prop"></a><div class="schemedoc-definition-comment">;; Return the value of key in the property list p-list.
;; In case the key does not exist in the property list, a fatal error will occur.
;; .parameter key is a symbol.
;; .parameter p-list a property list with symbols as keys.
;; .returns the first value of key in p-list
;; .misc Uses the function eq? for key comparions.
;; .internal-references "similar function" "defaulted-get-prop"
;; .pre-condition p-list is of even length</div><a name="get-prop"></a><span><a href="../general.html#get-prop"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(get-prop key p-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#find-in-property-list" title="general">find-in-property-list</a> key p-list)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> res
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> res)))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> res)
            (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "Illformed property list:" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> p-list)))
        (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "Get-prop: Cannot find" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> key) "in the property list" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> p-list)))))

<a name="find-in-property-list"></a><div class="schemedoc-definition-comment">;; Does key exists a property name in the property list p-list?
;; If so, return a reference to the cons cell that holds key.</div><a name="find-in-property-list"></a><span><a href="../general.html#find-in-property-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-property-list key p-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> p-list) #f)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> key (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> p-list)) p-list)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> p-list))) (<a class="applied-name" href="general-1.html#find-in-property-list" title="general">find-in-property-list</a> key (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> p-list)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "Illformed property list:" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> p-list)))))

<a name="defaulted-get-prop"></a><div class="schemedoc-definition-comment">;; Return the value of key in the property list p-list. If key is not present in p-list, return default.
;; .internal-references "similar function" "get-prop"
;; .pre-condition p-list is a list of even length</div><a name="defaulted-get-prop"></a><span><a href="../general.html#defaulted-get-prop"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(defaulted-get-prop key p-list default)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#find-in-property-list" title="general">find-in-property-list</a> key p-list)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> res
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> res)))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> res)
            (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "Illformed property list:" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> p-list)))
        default)))

<a name="remove-prop!"></a><div class="schemedoc-definition-comment">;; Remove all instances of key and its values form the property list p-list. 
;; .returns the resulting, possible shorter, property list (a reduced copy of p-list).
;; .pre-condition p-list is a well-formed property list.
;; .misc This is a function, not a mutating procedure.</div><a name="remove-prop!"></a><span><a href="../general.html#remove-prop!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-prop! key p-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> p-list) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> key (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> p-list))
            (<a class="applied-name" href="general-1.html#remove-prop!" title="general">remove-prop!</a> key (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> p-list)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> p-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> p-list) (<a class="applied-name" href="general-1.html#remove-prop!" title="general">remove-prop!</a> key (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> p-list)))))))

<a name="remove-props!"></a><div class="schemedoc-definition-comment">;; Remove all instances of keys in key-list together with its values form the property list p-list. 
;; .returns the resulting, possible shorter, property list (a reduced copy of p-list).
;; .pre-condition p-list is a well-formed property list.
;; .misc This is a function, not a mutating procedure.</div><a name="remove-props!"></a><span><a href="../general.html#remove-props!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-props! key-list p-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> p-list) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX338" title="R5RS Scheme form">memq</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> p-list) key-list)
            (<a class="applied-name" href="general-1.html#remove-props!" title="general">remove-props!</a> key-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> p-list)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> p-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> p-list) (<a class="applied-name" href="general-1.html#remove-props!" title="general">remove-props!</a> key-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> p-list)))))))

<a name="alist-from-keys-and-values"></a><div class="schemedoc-definition-comment">;; Make an alist from a key-list and a val-list. 
;; .pre-condition the lengths of the two input lists are equal.</div><a name="alist-from-keys-and-values"></a><span><a href="../general.html#alist-from-keys-and-values"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(alist-from-keys-and-values key-list val-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> key-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> val-list))
      (<a class="applied-name" href="general-1.html#alist-from-keys-and-values-1" title="general">alist-from-keys-and-values-1</a> key-list val-list)
      (error "alist-from-keys-and-values: key and val list do not have same lengths")))

<a name="alist-from-keys-and-values-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(alist-from-keys-and-values-1 key-list val-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> key-list)
      '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> key-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> val-list))
            (<a class="applied-name" href="general-1.html#alist-from-keys-and-values-1" title="general">alist-from-keys-and-values-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> key-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> val-list)))))

<a name="propertylist-to-alist"></a><div class="schemedoc-definition-comment">;; Make and return an association list from a property list plist.</div><a name="propertylist-to-alist"></a><span><a href="../general.html#propertylist-to-alist"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(propertylist-to-alist plist)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> plist)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> plist) '())
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 lgt) (error "propertylist-to-a-list called with list of odd length. A property list is always of even length"))
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> lgt 2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> plist) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> plist)) (<a class="applied-name" href="general-1.html#propertylist-to-alist" title="general">propertylist-to-alist</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> plist)))))))

<a name="alist-to-propertylist"></a><div class="schemedoc-definition-comment">;; Make and return a property list from an association list.</div><a name="alist-to-propertylist"></a><span><a href="../general.html#alist-to-propertylist"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(alist-to-propertylist alist)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> alist) '())
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> alist)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> alist)) (<a class="applied-name" href="general-1.html#alist-to-propertylist" title="general">alist-to-propertylist</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> alist)))))))

<a name="every-second-element"></a><div class="schemedoc-definition-comment">;; Return every second element of list, starting with the first element.
;; This function is useful to extract the keys or values of a property list.</div><a name="every-second-element"></a><span><a href="../general.html#every-second-element"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(every-second-element lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="applied-name" href="general-1.html#every-second-element" title="general">every-second-element</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> lst))))))

<a name="but-props"></a><div class="schemedoc-definition-comment">;; Return those property names and values of prop-list which are not in eliminations.
;; .parameter prop-list A well-formed property list, in which the property names are symbols.
;; .parameter eliminations A list of property names, where each property name is a symbol.</div><a name="but-props"></a><span><a href="../general.html#but-props"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(but-props prop-list eliminations)</span>
 (<a class="applied-name" href="general-1.html#but-props-1" title="general">but-props-1</a> prop-list eliminations '()))

<a name="but-props-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(but-props-1 prop-list eliminations res)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> prop-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> prop-list)) (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "but-props called with ill-formed property list (odd number of elements)"))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">name</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> prop-list))
                   (<span class="local-name-binding">val</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> prop-list)))
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX338" title="R5RS Scheme form">memq</a> name eliminations) 
                   (<a class="applied-name" href="general-1.html#but-props-1" title="general">but-props-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> prop-list) eliminations res)
                   (<a class="applied-name" href="general-1.html#but-props-1" title="general">but-props-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> prop-list) eliminations (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> val (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> name res))))))))

<a name="property-subset"></a><div class="schemedoc-definition-comment">;; Return those property key/value pairs of the proper list prop-list whose keys are member of keylist.
;; Comparison is done by the function memq.</div><a name="property-subset"></a><span><a href="../general.html#property-subset"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(property-subset prop-list keylist)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> prop-list) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX338" title="R5RS Scheme form">memq</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> prop-list) keylist)
         (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> prop-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> prop-list) (<a class="applied-name" href="general-1.html#property-subset" title="general">property-subset</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> prop-list) keylist))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#property-subset" title="general">property-subset</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> prop-list) keylist))))


<a name="pair-up"></a><div class="schemedoc-definition-comment">;; Return a list of pairs of elements from lst1 and lst2.
;; In other words, return an association list with keys from lst1 and values from lst2.
;; The list is as long as the shortest of lst1 and lst2.</div><a name="pair-up"></a><span><a href="../general.html#pair-up"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(pair-up lst1 lst2)</span>
  (<a class="applied-name" href="general-1.html#pair-up-1" title="general">pair-up-1</a> lst1 lst2 '()))

<a name="pair-up-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(pair-up-1 lst1 lst2 res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#pair-up-1" title="general">pair-up-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2)) res)))))

<a name="symbolize-key"></a><div class="schemedoc-definition-comment">;; A function which converts the key position in an a-lists to a symbol.
;; .parameter key-value-pair a pair, such as ("key" . "val")
;; .returns a pair (key . "val")</div><a name="symbolize-key"></a><span><a href="../general.html#symbolize-key"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(symbolize-key key-value-pair)</span>
 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="applied-name" href="general-1.html#as-symbol" title="general">as-symbol</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> key-value-pair)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> key-value-pair)))


<div class="schemedoc-section-comment">;;; Filter and accumulation functions. 
;;; This sections provides variants of the very useful higher order filtering function.</div>
<a name="filter"></a><div class="schemedoc-definition-comment">;; Filter a list lst by means of the predicate pred. Preserves the ordering of elements in lst.
;; .returns the elements in lst that fulfills the predicate pred.
;; .misc Based on a tail recursive traversal of lst.
;; .internal-references "similar function" "filter-no-ordering"</div><a name="filter"></a><span><a href="../general.html#filter"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(filter pred lst)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#filter-help" title="general">filter-help</a> pred lst '())))

<a name="filter-no-ordering"></a><div class="schemedoc-definition-comment">;; Like filter, but the ordering among elements in the resulting list is unknown and arbitrary.
;; Actually returns filtered list in reverse order. OK in situations,
;; where a boolean result is needed: Are there anything passing the filter?
;; .internal-references "similar function" "filter"</div><a name="filter-no-ordering"></a><span><a href="../general.html#filter-no-ordering"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(filter-no-ordering pred lst)</span>
  (<a class="applied-name" href="general-1.html#filter-help" title="general">filter-help</a> pred lst '()))

<a name="filter-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(filter-help pred lst res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) res)
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) (<a class="applied-name" href="general-1.html#filter-help" title="general">filter-help</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#filter-help" title="general">filter-help</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) res))))


<span class="comment">; October 5, 2005: mapping-filter generalized to several lists (of equal lengths).</span><br />
<a name="mapping-filter"></a><div class="schemedoc-definition-comment">;; Map and filter the lists in the parameter lists by means of the predicate pred.
;; In the same ways as for the native map function of Scheme, lists must be a list of lists, and pred must be a function taking as many arguments as there are lists and returning a single value. If more than one list is given, then they must all be the same length. 
;; If the predicate pred returns a true value v on the elements in lists, return v instead of e (this is the mapping effect). 
;; Only return those mapped elements that fullfil pred.
;; .misc Remember that any non-#f element counts as the true (#t) value.</div><a name="mapping-filter"></a><span><a href="../general.html#mapping-filter"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(mapping-filter pred . lists)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#mapping-filter-help" title="general">mapping-filter-help</a> pred lists '())))

<a name="mapping-filter-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(mapping-filter-help pred lists res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lists))
      res
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">pred-appl</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lists))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> pred-appl 
            (<a class="applied-name" href="general-1.html#mapping-filter-help" title="general">mapping-filter-help</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lists) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> pred-appl res))
            (<a class="applied-name" href="general-1.html#mapping-filter-help" title="general">mapping-filter-help</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lists) res)))))

<span class="comment">; accumulate-right contributed by ttn@iblet.glug.org, November 28, 2002.</span><br />
<a name="accumulate-right"></a><div class="schemedoc-definition-comment">;; A higher-order function which right accumulates the list lst by means of the binary function f, 
;; using init as the initial value of the accumulation.
;; .misc This function is iterative.</div><a name="accumulate-right"></a><span><a href="../general.html#accumulate-right"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(accumulate-right f init lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> <span class="local-name-binding">loop</span> ((<span class="local-name-binding">lst</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> lst)) (<span class="local-name-binding">acc</span> init))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst)
	acc
	(loop (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) acc)))))


<div class="schemedoc-section-comment">;;; Mapping functions.
;;; Here is a set of generalized mapping functions. These functions are all similar to map (which may take an arbitrary number of lists).
;;; Notice however, that map2, map3, etc do not require all lists to be of equal lengths.</div>
<a name="map2"></a><div class="schemedoc-definition-comment">;; Like map, but maps f on two lists. 
;; .returns Returns a list of length equal to the length of the shortest of the input lists.</div><a name="map2"></a><span><a href="../general.html#map2"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(map2 f lst1 lst2)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2)) '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2)) 
            (<a class="applied-name" href="general-1.html#map2" title="general">map2</a> f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2)))))

<a name="map3"></a><div class="schemedoc-definition-comment">;; Like map, but maps f on three lists
;; .returns Returns a list of length equal to the length of the shortest of the input lists.</div><a name="map3"></a><span><a href="../general.html#map3"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(map3 f lst1 lst2 lst3)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst3)) '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst3)) 
            (<a class="applied-name" href="general-1.html#map3" title="general">map3</a> f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst3)))))

<a name="map4"></a><div class="schemedoc-definition-comment">;; Like map, but maps f on four lists
;; .returns Returns a list of length equal to the length of the shortest of the input lists.</div><a name="map4"></a><span><a href="../general.html#map4"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(map4 f lst1 lst2 lst3 lst4)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst3)  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst4)) '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst3) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst4)) 
            (<a class="applied-name" href="general-1.html#map4" title="general">map4</a> f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst3) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst4)))))

<a name="map5"></a><div class="schemedoc-definition-comment">;; Like map, but maps f on five lists
;; .returns Returns a list of length equal to the length of the shortest of the input lists.</div><a name="map5"></a><span><a href="../general.html#map5"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(map5 f lst1 lst2 lst3 lst4 lst5)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst3)  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst4) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst5)) '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst3) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst4) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst5) ) 
            (<a class="applied-name" href="general-1.html#map5" title="general">map5</a> f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst3) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst4) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst5)))))



<div class="schemedoc-section-comment">;;; Other higher-order functions.</div>
<a name="negate"></a><div class="schemedoc-definition-comment">;; A higher order functions which negates the predicate p. Negate accepts a predicate and returns the negated predicate.</div><a name="negate"></a><span><a href="../general.html#negate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(negate p)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>) 
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (p x) #f #t)))

<a name="disjunction"></a><div class="schemedoc-definition-comment">;; Form the disjunction (logical or) of the two predicates p and q.
;; .returns a predicate</div><a name="disjunction"></a><span><a href="../general.html#disjunction"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(disjunction p q)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>)
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (p x) (q x))))

<a name="conjunction"></a><div class="schemedoc-definition-comment">;; Form the conjunction (logical and) of the two predicates p and q.
;; .returns a predicate</div><a name="conjunction"></a><span><a href="../general.html#conjunction"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(conjunction p q)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>)
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (p x) (q x))))

<span class="comment">; Old version of compose:
; Return a composed function which applies f on g
; Both f and g are supposed to take a single argument.
; (define (compose f g)
;  (lambda (x)
;    (f (g x))))</span><br />
<a name="compose"></a><div class="schemedoc-definition-comment">;; Compose a list of functions to a single function.
;; Each function in the list takes a single parameter.
;; Handles the typical case of two functions manually to achieve better efficiency.
;; .pre-condition f-list is a proper list of length ast least one.</div><a name="compose"></a><span><a href="../general.html#compose"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(compose . f-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> f-list)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> f-list))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> f-list))
	 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">f</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> f-list)) 
	       (<span class="local-name-binding">g</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> f-list)))
	   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>) (f (g x)))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>)
		 ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> f-list)
		  ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="applied-name" href="general-1.html#compose" title="general">compose</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> f-list)) x))))))


<a name="generate-leq"></a><div class="schemedoc-definition-comment">;; Generate a less than or equal predicate from the enumeration-order.
;; If p is the generated predicate, (p x y) is true if and only if
;; (selector x) comes before (or at the same position) as (selector y)
;; in the enumeration-order. Thus, (selector x) is assumed to give a
;; value in enumeration-order. Comparison with elements in the enumeration-list
;; is done with el-eq?
;; .form (generate-leq enumeration-order selector [el-eq?])</div><a name="generate-leq"></a><span><a href="../general.html#generate-leq"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(generate-leq enumeration-order selector . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">el-eq?</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a>)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span> <span class="local-name-binding">y</span>)
     <span class="comment">; x and y supposed to be elements in enumeration order</span><br />     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">x-index</span> (<a class="applied-name" href="general-1.html#list-index" title="general">list-index</a> (selector x) enumeration-order el-eq?))
           (<span class="local-name-binding">y-index</span> (<a class="applied-name" href="general-1.html#list-index" title="general">list-index</a> (selector y) enumeration-order el-eq?)))
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> x-index y-index)))))

<a name="list-index"></a><span class="comment">; A helping function of generate-leq.
; Return the position of e in lst. First is 1
; compare with el-eq?
; if e is not member of lst return (+ 1 (length lst))</span><br /><a name="list-index"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-index e lst el-eq?)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) 1)
       ((el-eq? (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) e) 1)
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 (<a class="applied-name" href="general-1.html#list-index" title="general">list-index</a> e (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) el-eq?)))))

<a name="curry-generalized"></a><div class="schemedoc-definition-comment">;; Generalize f with ad hoc currying. 
;; f is a function which, in its native form, takes two or more parameters.
;; The generalization allows f to act as a curried function. In case (curry-generalized f)
;; only receives a single parameter, it returns a lambda function which waits for the 
;; remaining parameters.
;; If two or more parameters are passed to f, f is applied on the parameters; In this case
;; (curry-generalized f) is equivalent to f.
;; .example (define gmap (curry-generalized map))
;; .example (define gfilter (curry-generalized filter))</div><a name="curry-generalized"></a><span><a href="../general.html#curry-generalized"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(curry-generalized f)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> <span class="local-name-binding">rest</span>
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> rest) 1) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> <span class="local-name-binding">lst</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> f (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> rest) lst))))
          ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> rest) 2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> f rest)))))

<div class="schemedoc-section-comment">;;; List and Sexpr functions.</div>
<a name="number-interval"></a><div class="schemedoc-definition-comment">;; Return a list of all numbers from f to t. Return the empty list if f is greater than t.</div><a name="number-interval"></a><span><a href="../general.html#number-interval"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(number-interval f t)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> f t) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> f (<a class="applied-name" href="general-1.html#number-interval" title="general">number-interval</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> f 1) t)) '()))


<a name="proper-part"></a><div class="schemedoc-definition-comment">;; Return the proper part of an S-expression</div><a name="proper-part"></a><span><a href="../general.html#proper-part"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(proper-part lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst)))  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="applied-name" href="general-1.html#proper-part" title="general">proper-part</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst))))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) '()))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> '())))

<a name="first-improper-part"></a><div class="schemedoc-definition-comment">;; Return the first improper part of an S-expression</div><a name="first-improper-part"></a><span><a href="../general.html#first-improper-part"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(first-improper-part lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst)))  (<a class="applied-name" href="general-1.html#first-improper-part" title="general">first-improper-part</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst)))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Troubles in first-improper-part:" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst))))))



<a name="make-list"></a><div class="schemedoc-definition-comment">;; Return a list of n elements, each being el</div><a name="make-list"></a><span><a href="../general.html#make-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-list n el)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 0) '() (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> el (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1) el))))

<a name="replicate-to-length"></a><div class="schemedoc-definition-comment">;; Replicate lst cyclically to a list of length lgt</div><a name="replicate-to-length"></a><span><a href="../general.html#replicate-to-length"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(replicate-to-length lst lgt)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#replicate-to-length-1" title="general">replicate-to-length-1</a> lst lst '() 0 lgt)))

<a name="replicate-to-length-1"></a><span class="comment">; helping function to replicate-to-length
; original-lst is constant through this function.
; elements are taken out of lst
; the result is accumulated up in res
; count goes from 0 to lgt</span><br /><a name="replicate-to-length-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(replicate-to-length-1 original-lst lst res count lgt)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="applied-name" href="general-1.html#replicate-to-length-1" title="general">replicate-to-length-1</a> original-lst original-lst res count lgt))
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> count lgt) (<a class="applied-name" href="general-1.html#replicate-to-length-1" title="general">replicate-to-length-1</a> original-lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 count) lgt))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> res)))


<a name="flatten"></a><div class="schemedoc-definition-comment">;; Flatten a list of lists to one list.</div><a name="flatten"></a><span><a href="../general.html#flatten"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(flatten lst-of-lst)</span>
  (<a class="applied-name" href="general-1.html#accumulate-right" title="general">accumulate-right</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> '() lst-of-lst))

<a name="sum-list"></a><div class="schemedoc-definition-comment">;; Add all elments in a list of numbers</div><a name="sum-list"></a><span><a href="../general.html#sum-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sum-list lst)</span>
  (<a class="applied-name" href="general-1.html#accumulate-right" title="general">accumulate-right</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 0 lst))



<a name="merge-lists"></a><div class="schemedoc-definition-comment">;; Merge list1 and list2. Let e1 be the head of list1 and e2 the head of list2.
;; take e2 if (pred e1 e2) holds. Else e1</div><a name="merge-lists"></a><span><a href="../general.html#merge-lists"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(merge-lists list1 list2 pred)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> list1) list2)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> list2) list1)
       ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> list1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> list2)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> list2) (<a class="applied-name" href="general-1.html#merge-lists" title="general">merge-lists</a> list1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> list2) pred)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> list1) (<a class="applied-name" href="general-1.html#merge-lists" title="general">merge-lists</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> list1) list2 pred)))))

<a name="merge-lists-simple"></a><div class="schemedoc-definition-comment">;; Merge the two lists lst1 and lst2. lst1 provides the first element.
;; When the shortets of the lists is exhausted, insert the rest of the other list.
;; .example (merge-lists-simple '(a b c d)  '(1 2 3))  =&gt; (a 1 b 2 c 3 d)</div><a name="merge-lists-simple"></a><span><a href="../general.html#merge-lists-simple"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(merge-lists-simple lst1 lst2)</span>
 (<a class="applied-name" href="general-1.html#merge-lists-simple-1" title="general">merge-lists-simple-1</a> lst1 lst2 '()))

<a name="merge-lists-simple-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(merge-lists-simple-1 lst1 lst2 res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> lst2) res)))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> lst1) res)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#merge-lists-simple-1" title="general">merge-lists-simple-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) res ))))))

<a name="find-in-list"></a><div class="schemedoc-definition-comment">;; A simple linear list search function.
;; Return the first element which satisfies the predicate pred.
;; If no such element is found, return #f.
;; Tail recursive and iterative.
;; .internal-references "Similar string function" "find-in-string-by-predicate"</div><a name="find-in-list"></a><span><a href="../general.html#find-in-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-list pred lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) #f)
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-in-list" title="general">find-in-list</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst)))))

<a name="traverse-cons-cells"></a><div class="schemedoc-definition-comment">;; Return the list of all cons cells reachable from cell which satisfy pred.
;; If a cell c is accepted by the predicate, the cells of (cdr cell) are also examined for matches.
;; .parameter pred a cons-cell predicate.
;; .parameter cell a pair (such as a list).
;; .pre-condition cell is a cons cell (satisfies pair?)</div><a name="traverse-cons-cells"></a><span><a href="../general.html#traverse-cons-cells"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(traverse-cons-cells pred cell)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> cell)) '())
        ((pred cell) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> cell (<a class="applied-name" href="general-1.html#traverse-cons-cells" title="general">traverse-cons-cells</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> cell))))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> cell)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> cell)))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> (<a class="applied-name" href="general-1.html#traverse-cons-cells" title="general">traverse-cons-cells</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> cell)) (<a class="applied-name" href="general-1.html#traverse-cons-cells" title="general">traverse-cons-cells</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> cell))))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> cell))
            (<a class="applied-name" href="general-1.html#traverse-cons-cells" title="general">traverse-cons-cells</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> cell)))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> cell))
            (<a class="applied-name" href="general-1.html#traverse-cons-cells" title="general">traverse-cons-cells</a> pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> cell)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> '())))

<a name="butlast"></a><div class="schemedoc-definition-comment">;; Return all but the last element of a list. Quick and dirty version.</div><a name="butlast"></a><span><a href="../general.html#butlast"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(butlast lst)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> lst))))

<a name="last"></a><div class="schemedoc-definition-comment">;; Return the last element of a list. Quick and dirty version.</div><a name="last"></a><span><a href="../general.html#last"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(last lst)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> lst)))

<a name="remove-duplicates"></a><div class="schemedoc-definition-comment">;; Remove duplicate elements from list. A non-destructive function.
;; This function uses the Scheme function equal? (via the Scheme function member) for comparison of elements.
;; .example (remove-duplicates '(1 2 3 4 5)) =&gt; (1 2 3 4 5)
;; .example (remove-duplicates '(1 2 3 2 3 4 5)) =&gt; (1 2 3 4 5)</div><a name="remove-duplicates"></a><span><a href="../general.html#remove-duplicates"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates lst)</span>
 (<a class="applied-name" href="general-1.html#remove-duplicates-help" title="general">remove-duplicates-help</a> lst '()))

<a name="remove-duplicates-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates-help lst res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX340" title="R5RS Scheme form">member</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res) (<a class="applied-name" href="general-1.html#remove-duplicates-help" title="general">remove-duplicates-help</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) res))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#remove-duplicates-help" title="general">remove-duplicates-help</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res)))))

<a name="remove-duplicates-with-selection"></a><div class="schemedoc-definition-comment">;; A variant of remove-duplicates with a selector function.
;; This function applies a selector function before comparisons and member is called.
;; This function uses equal? for comparison of elements.</div><a name="remove-duplicates-with-selection"></a><span><a href="../general.html#remove-duplicates-with-selection"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates-with-selection lst selector)</span>
 (<a class="applied-name" href="general-1.html#remove-duplicates-with-selection-help" title="general">remove-duplicates-with-selection-help</a> lst '() '() selector))

<a name="remove-duplicates-with-selection-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates-with-selection-help lst res selected-res selector)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX340" title="R5RS Scheme form">member</a> (selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) selected-res)
            (<a class="applied-name" href="general-1.html#remove-duplicates-with-selection-help" title="general">remove-duplicates-with-selection-help</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) res selected-res selector))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#remove-duplicates-with-selection-help" title="general">remove-duplicates-with-selection-help</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res)  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) selected-res) selector ))))

<a name="element-before"></a><div class="schemedoc-definition-comment">;; Return the element of lst just before el, or #f if no such element exists.
;; More precisely, return the element of lst just before the element e, where e contains el in the sense that (eq? (selector e) el).
;; Via use of the optional parameter, comparison can be done by use of another function than eq?.
;; .form (element-before el lst selector [eq-pred])
;; .parameter el The element constituent that we are looking for.
;; .parameter lst The list to search.
;; .parameter selector A function that selects a constituent of an element of the list.
;; .parameter eq-pred The equality predicate on list constituents.\
;;  Can be used to compare el with (selector e) for any element e in lst. Defaults to eq?.
;; .returns An element of the list lst, preceding the element containing el.\
;;  Or #f in case such an element does not exist.</div><a name="element-before"></a><span><a href="../general.html#element-before"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(element-before el lst selector . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">eq-pred</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a>)))
  (<a class="applied-name" href="general-1.html#element-before-1" title="general">element-before-1</a> el lst selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) eq-pred)))

<a name="element-before-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(element-before-1 el lst selector lgt eq-pred)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> lgt 1) #f)
        ((eq-pred el (selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst))) #f)
        ((eq-pred el (selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> lst))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#element-before-1" title="general">element-before-1</a> el (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) eq-pred))))

<a name="element-after"></a><div class="schemedoc-definition-comment">;; Return the element of lst just after el, or #f if no such element exists.
;; More precisely, return the element of lst just after the element e, where e contains el in the sense that (eq? (selector e) el).
;; Via use of the optional parameter, comparison can be done by use of another function than eq?.
;; .form (element-after el lst selector [eq-pred])
;; .parameter el The element constituent that we are looking for.
;; .parameter lst The list to search.
;; .parameter selector A function that selects a constituent of an element of the list.
;; .parameter eq-pred The equality predicate on list constituents. Can be used to compare el with (selector e) for any element e in lst. Defaults to eq?.
;; .returns An element of the list lst, following the element containing el. Of #f in case such an element does not exist.</div><a name="element-after"></a><span><a href="../general.html#element-after"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(element-after el lst selector . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">eq-pred</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a>)))
  (<a class="applied-name" href="general-1.html#element-after-1" title="general">element-after-1</a> el lst selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) eq-pred)))

<a name="element-after-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(element-after-1 el lst selector lgt eq-pred)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> lgt 1) #f)
        ((eq-pred el (selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> lst))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#element-after-1" title="general">element-after-1</a> el (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) selector (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) eq-pred))))


<a name="list-difference"></a><div class="schemedoc-definition-comment">;; Remove the elements of lst2 from lst1. 
;; This function is a non-destructive function.
;; .form (list-difference lst1 lst2 [is-eq?])
;; .parameter lst1 The list from which lst1 is subtracted
;; .parameter lst2 The list to subtract from lst1
;; .parameter is-eq? the equalilty function used for element comparison. The default comparison function is eq?
;; .returns The elements in lst1 which are not member of lst2</div><a name="list-difference"></a><span><a href="../general.html#list-difference"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-difference lst1 lst2 . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">is-eq?</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a>)))
  (<a class="applied-name" href="general-1.html#list-difference-1" title="general">list-difference-1</a> lst1 lst2 '() is-eq?)))

<a name="list-difference-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-difference-1 lst1 lst2 res eq-pred)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) lst2 eq-pred) (<a class="applied-name" href="general-1.html#list-difference-1" title="general">list-difference-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) lst2 res eq-pred))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#list-difference-1" title="general">list-difference-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) lst2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1) res) eq-pred))))


<a name="sublist-by-rows"></a><div class="schemedoc-definition-comment">;; Return a list of lists of elements from lst.
;; Each sub list is of length n.
;; Take elements consequtive (by rows) and put them into sublists.
;; .internal-references "More general function" "sublist-by-predicate"</div><a name="sublist-by-rows"></a><span><a href="../general.html#sublist-by-rows"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-rows n lst)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 0) (error  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "sublist-by-rows: Cannot deal with row numbers less than or equal to zero: " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n))))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> lgt n) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> lst))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#sublist-by-rows-1" title="general">sublist-by-rows-1</a> n lst 0 '() '())))))

<a name="sublist-by-rows-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-rows-1 n lst m res RESULT)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> res)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> RESULT))  <span class="comment">; <span><a name="sublist-by-rows-1-@a"></a> @a</span></span><br />        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> res))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res) RESULT)))    <span class="comment">; <span><a name="sublist-by-rows-1-@b"></a> @b</span></span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> m n ) (<a class="applied-name" href="general-1.html#sublist-by-rows-1" title="general">sublist-by-rows-1</a> n lst 0 '() (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res) RESULT)))         <span class="comment">; <span><a name="sublist-by-rows-1-@c"></a> @c</span></span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> m n) (<a class="applied-name" href="general-1.html#sublist-by-rows-1" title="general">sublist-by-rows-1</a> n (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> m 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res) RESULT)) <span class="comment">; <span><a name="sublist-by-rows-1-@d"></a> @d</span></span><br />        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (error "sublist-by-rows-1: Should not happen"))))                       

<a name="sublist-by-2columns"></a><div class="schemedoc-definition-comment">;; Return sublists of lst in two column format. Thus each produced sublist is of length 2.
;; Good for presentation of the list in two columns, column by column.
;; In cases there is an uneven number of elements in lst, we add extra (the second parameter).</div><a name="sublist-by-2columns"></a><span><a href="../general.html#sublist-by-2columns"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-2columns lst extra)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst)
     '()
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst))
         (<span class="local-name-binding">lst1</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX246" title="R5RS Scheme form">even?</a> lgt) lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> extra))))
         (<span class="local-name-binding">row-sublst</span> (<a class="applied-name" href="general-1.html#sublist-by-rows" title="general">sublist-by-rows</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX246" title="R5RS Scheme form">even?</a> lgt) lgt (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 lgt)) 2) lst1)) <span class="comment">; <span><a name="sublist-by-2columns-@i"></a> @i</span></span><br />        )
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <span class="comment">; <span><a name="sublist-by-2columns-@j"></a> @j</span></span><br />      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">e1</span> <span class="local-name-binding">e2</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> e1 e2))
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> row-sublst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> row-sublst)))))

<a name="sublist-by-columns"></a><div class="schemedoc-definition-comment">;; Return sublists of lst in an n column format. Thus each produced sublist is of length n
;; (the first parameter).
;; In cases there is not enough elements, we add extra (the last parameter).</div><a name="sublist-by-columns"></a><span><a href="../general.html#sublist-by-columns"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-columns n lst extra)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst)
     '()
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst))
         (<span class="local-name-binding">q</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> lgt n))
         (<span class="local-name-binding">lst1</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#multiplum-of" title="general">multiplum-of</a> lgt n) lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> lst (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> q 1) n) lgt) extra)))) <span class="comment">; <span><a name="sublist-by-columns-@a"></a> @a</span></span><br />         (<span class="local-name-binding">rows</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#multiplum-of" title="general">multiplum-of</a> lgt n) q (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> q 1)))
         (<span class="local-name-binding">row-sublst</span> (<a class="applied-name" href="general-1.html#sublist-by-rows" title="general">sublist-by-rows</a> rows lst1)))
    (<a class="applied-name" href="general-1.html#multi-pair" title="general">multi-pair</a> row-sublst))))

<a name="multi-pair"></a><div class="schemedoc-definition-comment">;; Pair up first elements, second elements of a list of lists.
;; All first elements of the sublists are handled first, whereafter
;; we take all second elements, etc. 
;; .parameter lst-of-lst A list of lists.
;; .pre-condition All lists in lst-of-list are of equal lengths.</div><a name="multi-pair"></a><span><a href="../general.html#multi-pair"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(multi-pair lst-of-lst)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst-of-lst)) '())
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">cars</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst-of-lst))
                    (<span class="local-name-binding">cdrs</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst-of-lst)))
                (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> cars (<a class="applied-name" href="general-1.html#multi-pair" title="general">multi-pair</a> cdrs))))))

<a name="sublist-by-predicate"></a><div class="schemedoc-definition-comment">;; Return a list of sublists of elements from lst controlled by a predicate p.
;; The sublists are formed by examining elements from lst.  The predicate p decides
;; when to start a new sublist. Thus, when p evaluates to true (on some element e and its preceding element c) we start
;; a new sublist (whose first element becomes e). The predicate p is not activated on (car lst). 
;; This function generalizes sublist-by-rows.
;; .parameter lst An arbitrary list.
;; .parameter p A predicate of the form (lambda (cur prev n) ...) where cur is the current element, prev is the preceding element of cur,\
;;            and n is the number of elements preceding cur in the original list lst.</div><a name="sublist-by-predicate"></a><span><a href="../general.html#sublist-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-predicate lst p)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) '()) <span class="comment">; <span><a name="sublist-by-predicate-@a"></a> @a</span></span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> lst))  <span class="comment">; <span><a name="sublist-by-predicate-@b"></a> @b</span>special case: sublist the only element.</span><br />        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#sublist-by-predicate-1" title="general">sublist-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) p 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) '()))))


<a name="sublist-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-by-predicate-1 lst previous-el p n res RESULT)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> res)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> RESULT)) <span class="comment">; <span><a name="sublist-by-predicate-1-@d"></a> @d</span></span><br />        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> res))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res) RESULT))) <span class="comment">; <span><a name="sublist-by-predicate-1-@e"></a> @e</span></span><br />        ((p (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) previous-el n)   (<a class="applied-name" href="general-1.html#sublist-by-predicate-1" title="general">sublist-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) p (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> n 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res) RESULT))) <span class="comment">; <span><a name="sublist-by-predicate-1-@f"></a> @f</span></span><br />        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                          (<a class="applied-name" href="general-1.html#sublist-by-predicate-1" title="general">sublist-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) p (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> n 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res) RESULT)))) <span class="comment">; <span><a name="sublist-by-predicate-1-@g"></a> @g</span></span><br />
<a name="remove-duplicates-by-predicate"></a><div class="schemedoc-definition-comment">;; Remove duplicates from lst.
;; A pair of duplicates satisfy the predicate p: (p element element) -&gt; boolean.
;; In case of duplicates, keep the first one in the result.</div><a name="remove-duplicates-by-predicate"></a><span><a href="../general.html#remove-duplicates-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates-by-predicate lst p)</span>
 (<a class="applied-name" href="general-1.html#remove-duplicates-by-predicate-1" title="general">remove-duplicates-by-predicate-1</a> lst p '()))

<a name="remove-duplicates-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(remove-duplicates-by-predicate-1 lst p res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res p) (<a class="applied-name" href="general-1.html#remove-duplicates-by-predicate-1" title="general">remove-duplicates-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p res))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#remove-duplicates-by-predicate-1" title="general">remove-duplicates-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res)))))

<a name="duplicates-by-predicate"></a><div class="schemedoc-definition-comment">;; Return the duplicates in lst. 
;; The duplicates are returned in the order of their fist occurence in lst.
;; Comparison of elements is done by the predicate (p element element) -&gt; boolean.</div><a name="duplicates-by-predicate"></a><span><a href="../general.html#duplicates-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(duplicates-by-predicate lst p)</span>
  (<a class="applied-name" href="general-1.html#duplicates-by-predicate-1" title="general">duplicates-by-predicate-1</a> lst p '()))

<a name="duplicates-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(duplicates-by-predicate-1 lst p res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p)
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res p)        <span class="comment">; always detected as duplicate once</span><br />                (<a class="applied-name" href="general-1.html#duplicates-by-predicate-1" title="general">duplicates-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p res)
                (<a class="applied-name" href="general-1.html#duplicates-by-predicate-1" title="general">duplicates-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#duplicates-by-predicate-1" title="general">duplicates-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p res))))  

<a name="member-by-predicate"></a><div class="schemedoc-definition-comment">;; Is el member of lst by means of the predicate p.
;; el is always passed as the first parameter to p.
;; If el is member, return the suffix of the list in which the first element (and el) satisfy the predicate.
;; Else return #f.
;; The element el and elements of lst are compared by p, el as the first one.
;; p: (el1, el2) -&gt; boolean</div><a name="member-by-predicate"></a><span><a href="../general.html#member-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(member-by-predicate el lst p)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) #f)
        ((p el (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) lst)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> el (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) p))))

<a name="list-intersection-by-predicate"></a><div class="schemedoc-definition-comment">;; Return the elements of lst1 an lst2 which belongs to both of the lists.
;; Elements will never occur more than once in the result.
;; Element comparsion is done by pred.
;; Performance: O (length lst1) x (length lst2).
;; .parameter pred: Element x Element -&gt; Boolean.
;; .example (list-intersection '(a b c d a) '(a d) eq?) = (a d)</div><a name="list-intersection-by-predicate"></a><span><a href="../general.html#list-intersection-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-intersection-by-predicate lst1 lst2 pred)</span>
 (<a class="applied-name" href="general-1.html#list-intersection-1" title="general">list-intersection-1</a> lst1 lst2 pred '()))

<a name="list-intersection-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-intersection-1 lst1 lst2 pred res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst1) (<a class="applied-name" href="general-1.html#remove-duplicates-by-predicate" title="general">remove-duplicates-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res) pred))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">el</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst1))
                     (<span class="local-name-binding">el-member-lst2</span> (<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> el lst2 pred)))
                (<a class="applied-name" href="general-1.html#list-intersection-1" title="general">list-intersection-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst1) lst2 pred (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> el-member-lst2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> el res) res))))))
  

<a name="cut-list-by-predicate"></a><div class="schemedoc-definition-comment">;; Cut the tail of lst; The tail to be cutted starts with an element which fulfils pred.
;; Notice that the first element which fulfils the predicate is not included in the resulting list.</div><a name="cut-list-by-predicate"></a><span><a href="../general.html#cut-list-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(cut-list-by-predicate lst pred)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) '())
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) '())
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="applied-name" href="general-1.html#cut-list-by-predicate" title="general">cut-list-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) pred)))))


<a name="subset-of-by-predicate"></a><div class="schemedoc-definition-comment">;; Return whether every element in set-list-1 (a list) is a member of set-list-2, compared by the comparator comp.
;; This corresponds to a subset operations on sets, represented by a list.
;; comp: el x el -&gt; boolean.</div><a name="subset-of-by-predicate"></a><span><a href="../general.html#subset-of-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(subset-of-by-predicate set-list-1 set-list-2 comp)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> set-list-1) #t)
        ((<a class="applied-name" href="general-1.html#member-by-predicate" title="general">member-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> set-list-1) set-list-2 comp) (<a class="applied-name" href="general-1.html#subset-of-by-predicate" title="general">subset-of-by-predicate</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> set-list-1) set-list-2 comp))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))


<a name="index-in-list-by-predicate"></a><div class="schemedoc-definition-comment">;; Return the index position of the fist occurrence of el in list. The first element is counted as element number 0.
;; If the element el is not in the list lst, return #f. 
;; Comparison of list elements is done by the binary comparison function c.
;; c: el x el -&gt; boolean.</div><a name="index-in-list-by-predicate"></a><span><a href="../general.html#index-in-list-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(index-in-list-by-predicate lst el c)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">index-in-list-by-predicate-1</span> 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span> <span class="local-name-binding">count</span>)
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) #f)
                     ((c (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) el) count)
                     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (index-in-list-by-predicate-1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> count 1)))))))
  (index-in-list-by-predicate-1  lst 0)))


<a name="sublistify"></a><div class="schemedoc-definition-comment">;; Divide the elements of lst into sublists of sublist-length.
;; In case that sublist-length does not divide (length lst) the last
;; sublist will be shorter than the others.
;; .example (sublistify '(1 2 3 4 5 6 7 8 9) 4) = ((1 2 3 4) (5 6 7 8) (9))</div><a name="sublistify"></a><span><a href="../general.html#sublistify"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublistify lst sublist-length)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) sublist-length)
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> lst)
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">first-sublist</span> (<a class="applied-name" href="general-1.html#list-prefix" title="general">list-prefix</a> lst sublist-length))
           (<span class="local-name-binding">rest-lst</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst sublist-length)))
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> first-sublist
             (<a class="applied-name" href="general-1.html#sublistify" title="general">sublistify</a> rest-lst sublist-length)))))

<a name="front-sublist"></a><div class="schemedoc-definition-comment">;; Return the first n elements of lst.
;; This function makes a shallow copy of the first n elements of lst. Thus, it allocates n new cons cells.
;; If n is equal or greater than the length of lst, lst is returned without any copying at all.
;; .misc Another function, list-prefix, exists which is almost identical to front-sublist. </div><a name="front-sublist"></a><span><a href="../general.html#front-sublist"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(front-sublist lst n)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)) lst (<a class="applied-name" href="general-1.html#front-sublist-1" title="general">front-sublist-1</a> lst n)))


<a name="front-sublist-1"></a><span class="comment">; A helping operation to front-sublist</span><br /><a name="front-sublist-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(front-sublist-1 lst n)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0) '())
       ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n 0) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="applied-name" href="general-1.html#front-sublist-1" title="general">front-sublist-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
       ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n 0) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst)) '())
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "front-sublist-1: Should not happen" lst n))))

<a name="front-sublist-while"></a><div class="schemedoc-definition-comment">;; Return a list prefix of lst, of which all elements satisfy the predicate ok?. 
;; The returned prefix has at most max-length elements.
;; This function makes a shallow copy of at most max-length elements of lst. Thus, it allocates a number of new cons cells.
;; .parameter lst An arbitrary list.
;; .parameter ok? A list element predicate, which is applied successively on elements of the list.
;; .parameter max-length An integer that gives the maximum number of elements to be returned by this function.
;; .returns A prefix of lst, of length at most max-length. All elements in the result satisfy the predicate ok?</div><a name="front-sublist-while"></a><span><a href="../general.html#front-sublist-while"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(front-sublist-while lst ok? max-length)</span>
  (<a class="applied-name" href="general-1.html#front-sublist-while-1" title="general">front-sublist-while-1</a> lst ok? max-length   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) '() 0))

<a name="front-sublist-while-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(front-sublist-while-1 lst ok? max-length   lst-lgt res length-res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 lst-lgt) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> max-length length-res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
        ((ok? (<a class="applied-name" href="general-1.html#first" title="general">first</a> lst))
           (<a class="applied-name" href="general-1.html#front-sublist-while-1" title="general">front-sublist-while-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) ok? max-length
                                lst-lgt (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="applied-name" href="general-1.html#first" title="general">first</a> lst) res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 length-res)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))))

<a name="rear-sublist"></a><div class="schemedoc-definition-comment">;; Return the last n elements of lst. 
;; This function returns a reference to an appropriate tail of lst, involving only the last n elements.
;; If n is equal to or larger than (length lst), just return lst.</div><a name="rear-sublist"></a><span><a href="../general.html#rear-sublist"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(rear-sublist lst n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lst-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n lst-lgt)
        lst
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">prefix-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lst-lgt n)))
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst prefix-lgt)))))


<a name="list-prefix"></a><span class="comment">; Return the list of the first n elements of lst.
; If n &gt; (length lst) just return lst. 
; .misc This function is almost identical to front-sublist.</span><br /><a name="list-prefix"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-prefix lst n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) n)
      lst
      (<a class="applied-name" href="general-1.html#list-prefix-1" title="general">list-prefix-1</a> lst n)))

<a name="list-prefix-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-prefix-1 lst n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0)
      '()
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) (<a class="applied-name" href="general-1.html#list-prefix-1" title="general">list-prefix-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))))


<a name="list-part"></a><div class="schemedoc-definition-comment">;; Return the sublist consisting of element a to element b of the list lst.
;; Both element number a and b are included in the resulting list. The first element counts as element number 1.
;; .example (list-part 3 5 '(a b c d e f g h)) = (c d e)
;; .pre-condition a &gt;= 1, a &lt;= b, b &lt;= (length lst), and a and b are postive integers.</div><a name="list-part"></a><span><a href="../general.html#list-part"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-part a b lst)</span>
  (<a class="applied-name" href="general-1.html#list-part-help" title="general">list-part-help</a> a b lst 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) '()))

<a name="list-part-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-part-help a b lst  i lgt res)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> i b) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> res))
       ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i a) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> i b) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst))) (<a class="applied-name" href="general-1.html#list-part-help" title="general">list-part-help</a> a b (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst) res)))
       ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> i a) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst)))  (<a class="applied-name" href="general-1.html#list-part-help" title="general">list-part-help</a> a b (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt res))
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "list-part error: " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> i))))))


<a name="sublist-of-list"></a><div class="schemedoc-definition-comment">;; The first element of the resulting list fullfils from-pred.
;; The last element is the element before the element that fullfils end-pred.
;; If from-pred is true on an element and to-pred is false on every element in list, a suffix of the list is returned.
;; In other cases, if one or both of the predicates return false on every element the empty list is returned</div><a name="sublist-of-list"></a><span><a href="../general.html#sublist-of-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(sublist-of-list lst from-pred end-pred)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lst-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst))
        (<span class="local-name-binding">i</span> (<a class="applied-name" href="general-1.html#find-index-in-list" title="general">find-index-in-list</a> lst from-pred))
        (<span class="local-name-binding">j</span> (<a class="applied-name" href="general-1.html#find-index-in-list" title="general">find-index-in-list</a> lst end-pred)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> i j)
            (<a class="applied-name" href="general-1.html#list-part" title="general">list-part</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) j lst))
          ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> i (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> j))
            (<a class="applied-name" href="general-1.html#list-part" title="general">list-part</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lst-lgt lst))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> '()))))

<a name="find-index-in-list"></a><div class="schemedoc-definition-comment">;; Find the index of the first element in lst that satisfies the element predicate pred.
;; The first element counts as number 0.</div><a name="find-index-in-list"></a><span><a href="../general.html#find-index-in-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-index-in-list lst pred)</span>
  (<a class="applied-name" href="general-1.html#find-index-in-list-1" title="general">find-index-in-list-1</a> lst pred 0))

<a name="find-index-in-list-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-index-in-list-1 lst pred i)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) #f)
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)) i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-index-in-list-1" title="general">find-index-in-list-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1)))))


<div class="schemedoc-section-comment">;;; Vector functions.</div>
<a name="binary-search-in-vector"></a><div class="schemedoc-definition-comment">;; Search for an element el in the sorted vector v.
;; More specifically, el is compared to (sel ve), where ve is a element from the vector v.
;; Comparison is done by the binary predicate el-eq? which works on selected values.
;; Thus (el-eq? (sel x) el) makes sense for an element x in the vector.
;; Ordering in the vector is defined by the binary 'less-than-equal predicate' el-leq?
;; which compares selected values. Thus (el-leq (sel x) (sel y)) makes sense for x and y
;; being elements in the vector v.
;; .parameter v The vector to search in.
;; .parameter el The element to search for in the vector. el is comparabel with (sel ve) for a given vector element.
;; .parameter sel A function that can be applied on vector elements. 
;; .parameter el-eq? An equality function that can be applied on el and on (sel ve) for a given vector element.
;; .parameter el-leq? A less than or equal function that can be applied on el and vector elements (sel ve).
;; .returns An element in the vector, if found as described above, or #f.</div><a name="binary-search-in-vector"></a><span><a href="../general.html#binary-search-in-vector"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(binary-search-in-vector v el sel el-eq? el-leq?)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX403" title="R5RS Scheme form">vector-length</a> v)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX403" title="R5RS Scheme form">vector-length</a> v))
      #f
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX128" title="R5RS Scheme form">do</a> ((up-idx   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1))
	   (low-idx  0)
	   )
	  ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (el-eq? el (sel (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2))))	<span class="comment">; hit</span><br />	       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> up-idx low-idx) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> up-idx (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 low-idx)) <span class="comment">; narrow interval</span><br />	       )
	   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((el-eq? el (sel (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2)))) <span class="comment">; mid</span><br />		  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2)))
		 ((el-eq? el (sel (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v low-idx))) <span class="comment">; low</span><br />		  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v low-idx))
		 ((el-eq? el (sel (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v up-idx))) <span class="comment">; up</span><br />		  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v up-idx))
		 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))
	(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((el-leq? el (sel (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX404" title="R5RS Scheme form">vector-ref</a> v (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2))))
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> up-idx (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2)))
	      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> low-idx (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> up-idx low-idx) 2))))))))


<div class="schemedoc-section-comment">;;; Conversion functions. 
;;; In this category we provide a number of useful conversion functions. Several of these are of the form (as-type xxx),
;;; where type determines the target type of the conversion.&lt;p&gt;
;;; This section includes a function number-in-base which converts a decimal number to a number in another number system.</div>
<a name="char-&gt;string"></a><div class="schemedoc-definition-comment">;; Convert a character to a string</div><a name="char-&gt;string"></a><span><a href="../general.html#char-&gt;string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(char-&gt;string ch)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> 1 ch))


<a name="as-string"></a><div class="schemedoc-definition-comment">;; Convert x to a string.
;; Conversion of numbers, symbols, strings, booleans, characters, vectors, proper lists and improper lists are supported.</div><a name="as-string"></a><span><a href="../general.html#as-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-string x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> x) (symbol->string x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x "true" "false"))   <span class="comment">; consider "#t" and "#f" as alternatives</span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX351" title="R5RS Scheme form">char?</a> x) (<a class="applied-name" href="general-1.html#char-&gt;string" title="general">char-&gt;string</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX331" title="R5RS Scheme form">list?</a> x)
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "(" 
               (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> x) (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> x) 1) " "))
               ")"))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX399" title="R5RS Scheme form">vector?</a> x)
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lst</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX406" title="R5RS Scheme form">vector-&gt;list</a> x)))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "#(" 
               (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> lst) (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst) 1) " "))
               ")")))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> x)
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "(" 
               (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a>
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">y</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> y) " ")) (<a class="applied-name" href="general-1.html#proper-part" title="general">proper-part</a> x))
               )
               " . " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="applied-name" href="general-1.html#first-improper-part" title="general">first-improper-part</a> x))
               ")"))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> "??")))

<a name="as-quoted-string"></a><div class="schemedoc-definition-comment">;; Convert x to a string, in which string constituents themselves are quoted.
;; Good for output and messages, in which strings should appear in string quotes.</div><a name="as-quoted-string"></a><span><a href="../general.html#as-quoted-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-quoted-string x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> x) (symbol->string x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="applied-name" href="general-1.html#string-it" title="general">string-it</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x "true" "false"))   <span class="comment">; consider "#t" and "#f" as alternatives</span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX351" title="R5RS Scheme form">char?</a> x) (<a class="applied-name" href="general-1.html#char-&gt;string" title="general">char-&gt;string</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX331" title="R5RS Scheme form">list?</a> x)
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "(" 
               (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="applied-name" href="general-1.html#as-quoted-string" title="general">as-quoted-string</a> x) (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> x) 1) " "))
               ")"))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> x)
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "(" 
               (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a>
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">y</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#as-quoted-string" title="general">as-quoted-string</a> y) " ")) (<a class="applied-name" href="general-1.html#proper-part" title="general">proper-part</a> x))
               )
               " . " (<a class="applied-name" href="general-1.html#as-quoted-string" title="general">as-quoted-string</a> (<a class="applied-name" href="general-1.html#first-improper-part" title="general">first-improper-part</a> x))
               ")"))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> "??")))

<a name="as-symbol"></a><div class="schemedoc-definition-comment">;; Convert x to a symbol. String, symbols, booleans, and characters are supported</div><a name="as-symbol"></a><span><a href="../general.html#as-symbol"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-symbol x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX349" title="R5RS Scheme form">string-&gt;symbol</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x (<a class="applied-name" href="general-1.html#as-symbol" title="general">as-symbol</a> "true") (<a class="applied-name" href="general-1.html#as-symbol" title="general">as-symbol</a> "false")))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX351" title="R5RS Scheme form">char?</a> x) (<a class="applied-name" href="general-1.html#as-symbol" title="general">as-symbol</a> (<a class="applied-name" href="general-1.html#char-&gt;string" title="general">char-&gt;string</a> x)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))

<a name="as-number"></a><div class="schemedoc-definition-comment">;; Convert x to a number. Strings, numbers, chars and booleans are supported.
;; Strings with digits are converted using string-&gt;number, chars are converted with char-&gt;integer, true is converted to 1, and false to 0.</div><a name="as-number"></a><span><a href="../general.html#as-number"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-number x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX294" title="R5RS Scheme form">string-&gt;number</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX351" title="R5RS Scheme form">char?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX367" title="R5RS Scheme form">char-&gt;integer</a> x))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x 1 0))  <span class="comment">; false -&gt; 0, true -&gt; 1</span><br />        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>
         (error
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Cannot convert to number "
                         (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> x))))))


<a name="as-char"></a><div class="schemedoc-definition-comment">;; Convert x to a character. Integers, strings, booleans and symbols are supported.
;; If x is an integer between 0 and 255 return ASCII char number x. If x is a string return the first character in the string (which is supposed to be non-empty).
;; If x is a boolean return the character #\t for true and #\f for false. If x is a symbol return the first character of the print name of the string. Else return #\?.</div><a name="as-char"></a><span><a href="../general.html#as-char"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-char x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX351" title="R5RS Scheme form">char?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX228" title="R5RS Scheme form">integer?</a> x) 
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> x 0) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> x 255)) 
               (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> x)
               #\?))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> x 0))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x #\t #\f))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> x)  (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> x)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #\?)))

<a name="as-list"></a><div class="schemedoc-definition-comment">;; Convert x to a list. 
;; This function converts strings to a list of substring, which in the original string are separated by spaces, newlines, or tabs.
;; .internal-references "more general function" "string-to-list"
;; .example (as-list "xy z abc ") =&gt; ("xy" "z" "abc")</div><a name="as-list"></a><span><a href="../general.html#as-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-list x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="applied-name" href="general-1.html#string-to-list" title="general">string-to-list</a> x (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> #\space (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 13) (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 10) #\tab)))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX331" title="R5RS Scheme form">list?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX319" title="R5RS Scheme form">pair?</a> x) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX399" title="R5RS Scheme form">vector?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX406" title="R5RS Scheme form">vector-&gt;list</a> x)) 
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> x))))

<a name="string-to-list"></a><div class="schemedoc-definition-comment">;; Convert a string to a list.
;; The second parameter is a list of separator characters.</div><a name="string-to-list"></a><span><a href="../general.html#string-to-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-to-list str element-separator-chars)</span>
 (<a class="applied-name" href="general-1.html#filter" title="general">filter</a> (<a class="applied-name" href="general-1.html#negate" title="general">negate</a> <a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a>)
  (<a class="applied-name" href="general-1.html#string-to-list-help" title="general">string-to-list-help</a> str "" '() element-separator-chars (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))))

<a name="string-to-list-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-to-list-help str next-el res-list element-separator-chars str-lgt)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 str-lgt)
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> next-el res-list))     <span class="comment">; add last 'rest element: next-el</span><br />     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">next-char</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0))
	   (<span class="local-name-binding">rest-string</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 1 str-lgt)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> 
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> next-char element-separator-chars) (<a class="applied-name" href="general-1.html#string-to-list-help" title="general">string-to-list-help</a> rest-string "" (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> next-el res-list) element-separator-chars (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> str-lgt 1)))
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#string-to-list-help" title="general">string-to-list-help</a> rest-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> next-el (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> next-char)) res-list element-separator-chars (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> str-lgt 1)))))))

<a name="as-boolean"></a><div class="schemedoc-definition-comment">;; Convert x to a boolean. The strings "false", "no", and "NO" are converted to #f. Other strings are converted to #t.</div><a name="as-boolean"></a><span><a href="../general.html#as-boolean"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-boolean x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> x "false") (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> x "no") (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> x "NO")) #f #t))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> x) x)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (error "Cannot convert to boolean"))))

<a name="turn-into-boolean"></a><div class="schemedoc-definition-comment">;; If x is considered true return #t else #f. 
;; See also as-boolean which is more versatile.
;; Recall that all values except #f, conveniently, act as a true value.</div><a name="turn-into-boolean"></a><span><a href="../general.html#turn-into-boolean"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(turn-into-boolean x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x #t #f))

<a name="as-01-boolean"></a><div class="schemedoc-definition-comment">;; Convert x to C-style boolean values, 0 or 1.
;; Numbers are treated in the following way: If x is 0 the result is 0. If x is not 0 the result is 1.
;; Else 1 is returned if x is considered as true in Scheme, and 0 is returned if x is considered as false in Scheme.
;; .returns Either the integer 0 (for false) or the integer 1 (for true). </div><a name="as-01-boolean"></a><span><a href="../general.html#as-01-boolean"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(as-01-boolean x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x)
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 x) 0 1))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> x 1 0))))

<a name="list-to-string"></a><div class="schemedoc-definition-comment">;; Return a string with the elements of str-lst separated by separator.
;; .parameter str-list A list of strings
;; .parameter separator A string which is used to separate the list elements in the resulting string.</div><a name="list-to-string"></a><span><a href="../general.html#list-to-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(list-to-string str-lst separator)</span>
  (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> 
     str-lst
     (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> str-lst) 1) separator)))

<a name="string-append-with-separator"></a><div class="schemedoc-definition-comment">;; Concatenate the strings in str-lst, and separate them by separator-str.
;; .parameter str-lst A list of strings
;; .parameter separator A string, a character or anything else that the function as-string can convert to a string.
;; .returns A string </div><a name="string-append-with-separator"></a><span><a href="../general.html#string-append-with-separator"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-append-with-separator str-lst separator)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">string-append-with-separator-1</span> 
             (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">str-lst</span> <span class="local-name-binding">lgt-lst</span> <span class="local-name-binding">sep</span> <span class="local-name-binding">res</span>)
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> lgt-lst 0) res)
                      ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> lgt-lst 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="general-1.html#first" title="general">first</a> str-lst)))
                      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (string-append-with-separator-1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> str-lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt-lst 1) sep (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="general-1.html#first" title="general">first</a> str-lst) sep)))))))
    (string-append-with-separator-1 str-lst (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> str-lst) (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> separator) "")))


<a name="number-in-base"></a><div class="schemedoc-definition-comment">;; Return the decimal number n in base. 
;; .parameter n     A positive decimal integer.
;; .parameter base  The base of the number system. A possitive integer greater than 1.
;; .returns         A string which represents n in the number system with base.
;; .misc By coincidence equivalent to the native Scheme function number-&gt;string.</div><a name="number-in-base"></a><span><a href="../general.html#number-in-base"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(number-in-base n base)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0) "0"
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ciffer-list</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#ciffers-in-base" title="general">ciffers-in-base</a> n base))))
     (<a class="applied-name" href="general-1.html#ciffer-output" title="general">ciffer-output</a> ciffer-list))))

<a name="ciffers-in-base"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ciffers-in-base n base)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0)
      '()
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">rem</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX260" title="R5RS Scheme form">modulo</a> n base))
            (<span class="local-name-binding">newn</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> n base)))
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> rem (<a class="applied-name" href="general-1.html#ciffers-in-base" title="general">ciffers-in-base</a> newn base)))))

<a name="ciffer-output"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ciffer-output ciffer-list)</span>
 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a>
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="applied-name" href="general-1.html#ciffer-translation" title="general">ciffer-translation</a> ciffer-list)))

<a name="ciffer-translation"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ciffer-translation c)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> c 9) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> c))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> c 9) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> c 33)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> c 87))))
        (t "?")))


<div class="schemedoc-section-comment">;;; String predicates.</div>
<span class="comment">; Is the string str empty
; (define (empty-string? str)
;  (= (string-length str) 0))</span><br />
<a name="empty-string?"></a><div class="schemedoc-definition-comment">;; Is the string str empty</div><a name="empty-string?"></a><span><a href="../general.html#empty-string?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(empty-string? str)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX381" title="R5RS Scheme form">string=?</a> str ""))

<a name="white-space-char-list"></a><div class="schemedoc-definition-comment">;; A list of characters considered as blank space characters</div><a name="white-space-char-list"></a><span><a href="../general.html#white-space-char-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">white-space-char-list</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> #\space (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 13) (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 10) #\tab))

<a name="blank-string?"></a><div class="schemedoc-definition-comment">;; Is the string str empty or blank. A blank string is composed of spaces, CRs, line feeds and tabs.</div><a name="blank-string?"></a><span><a href="../general.html#blank-string?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(blank-string? str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> str) 
      (<a class="applied-name" href="general-1.html#string-of-char-list?" title="general">string-of-char-list?</a> str <a class="applied-name" href="general-1.html#white-space-char-list" title="general">white-space-char-list</a>)))

<a name="numeric-string?"></a><div class="schemedoc-definition-comment">;; Returns if the string str is numeric.
;; More specifically, does str consist exclusively of the ciffers 0 through 9.
;; A non-false value of the optional parameter signed? allows an initial '+' or '-' char as well.
;; .form (numeric-string? str [signed?])</div><a name="numeric-string?"></a><span><a href="../general.html#numeric-string?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(numeric-string? str . optional-parameters)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">signed?</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameters #f)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> signed?
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0) #\+) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0) #\-))
            (<a class="applied-name" href="general-1.html#string-of-char-list?" title="general">string-of-char-list?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) ) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 )))
       (<a class="applied-name" href="general-1.html#string-of-char-list?" title="general">string-of-char-list?</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 )))))

<a name="string-of-char-list?"></a><div class="schemedoc-definition-comment">;; Are all characters in str member of char-list (a list of characters).</div><a name="string-of-char-list?"></a><span><a href="../general.html#string-of-char-list?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-of-char-list? str char-list)</span>
  (<a class="applied-name" href="general-1.html#string-of-char-list-1?" title="general">string-of-char-list-1?</a> str char-list 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))

<a name="string-of-char-list-1?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-of-char-list-1? str char-list i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt)
      #t
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i) char-list)
           (<a class="applied-name" href="general-1.html#string-of-char-list-1?" title="general">string-of-char-list-1?</a> str char-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))


<a name="string-of-negative-char-list?"></a><div class="schemedoc-definition-comment">;; Are all characters in str different from the characters in char list (a list of characters).</div><a name="string-of-negative-char-list?"></a><span><a href="../general.html#string-of-negative-char-list?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-of-negative-char-list? str char-list)</span>
  (<a class="applied-name" href="general-1.html#string-of-negative-char-list-1?" title="general">string-of-negative-char-list-1?</a> str char-list 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))

<a name="string-of-negative-char-list-1?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-of-negative-char-list-1? str char-list i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt)
      #t
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i) char-list))
           (<a class="applied-name" href="general-1.html#string-of-negative-char-list-1?" title="general">string-of-negative-char-list-1?</a> str char-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))

<a name="looking-at-substring?"></a><div class="schemedoc-definition-comment">;; Does str contain sub-str as substring, starting at position pos?
;; An efficient implementation without any string copying, only character comparsion.
;; .parameter str The string to examine.
;; .parameter sub-str The string to look for in str.
;; .parameter pos The position where the match will have to occur (a non-negative integer).
;; .returns A boolean value.</div><a name="looking-at-substring?"></a><span><a href="../general.html#looking-at-substring?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(looking-at-substring? str pos sub-str)</span>
  (<a class="applied-name" href="general-1.html#looking-at-substring-1?" title="general">looking-at-substring-1?</a> str pos sub-str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> sub-str)))

<a name="looking-at-substring-1?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(looking-at-substring-1? str pos sub-str i lgt1 lgt2)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">a</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i pos)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt2) #t)
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> a lgt1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i lgt2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str a) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> sub-str i)))
          (<a class="applied-name" href="general-1.html#looking-at-substring-1?" title="general">looking-at-substring-1?</a> str pos sub-str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt1 lgt2))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f))))

<a name="substring?"></a><div class="schemedoc-definition-comment">;; Is t a substring of s? This function is almost identical to substring-index 
;; which in tells at which position (if any) t occurs in s.
;; .parameter s The string to examine.
;; .parameter t The string we are looking for as a substring of s.
;; .returns A boolean value.
;; .internal-references "related function" "substring-index"</div><a name="substring?"></a><span><a href="../general.html#substring?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(substring? s t)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">i</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> s 0 t)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> i #t #f)))


<div class="schemedoc-section-comment">;;; Other string functions.
;;; Among the functions in this section you will find string search and replacement functions. </div>

<a name="split-on"></a><div class="schemedoc-definition-comment">;; Return a list of two strings taken from str. ch is a character.
;; The first is the prefix of str up to the first occurence of ch
;; The second is the suffix from ch to the end of str</div><a name="split-on"></a><span><a href="../general.html#split-on"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(split-on ch str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">sp</span> (<a class="applied-name" href="general-1.html#split-point" title="general">split-point</a> ch str)))
   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 sp)

         (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> sp 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))))

<a name="split-point"></a><div class="schemedoc-definition-comment">;; Return the character position where ch occurs the first time in str.
;; If it does not appear, the procedure returns #f.
;; This function allocates some temporary strings, and as such it is not efficient. 
;; Use find-in-string instead.
;; .internal-references "similar string find function" "substring-index"</div><a name="split-point"></a><span><a href="../general.html#split-point"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(split-point ch str)</span>
 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX417" title="R5RS Scheme form">call-with-current-continuation</a>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">exit</span>)
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> str "") #f)
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0)) 0)
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#split-point" title="general">split-point</a> ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))))
                  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> res)
                      (exit #f)
                      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 res))))))))

<a name="split-string-by-predicate"></a><div class="schemedoc-definition-comment">;; Split the string str into a list of strings.
;; Consequtive portions of the strings, in which each character satisfies the char predicate pred, separate the elements of the resulting list.</div><a name="split-string-by-predicate"></a><span><a href="../general.html#split-string-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(split-string-by-predicate str pred)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">p1</span> (<a class="applied-name" href="general-1.html#find-in-string-by-predicate" title="general">find-in-string-by-predicate</a> (<a class="applied-name" href="general-1.html#negate" title="general">negate</a> pred) str 0)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> str) '())
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> p1) '())
         (p1 (<a class="applied-name" href="general-1.html#split-string-by-predicate-1" title="general">split-string-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str p1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)) pred))
         (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> str))))

<a name="split-string-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(split-string-by-predicate-1 str pred)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">strlen</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
        (<span class="local-name-binding">p1</span> (<a class="applied-name" href="general-1.html#find-in-string-by-predicate" title="general">find-in-string-by-predicate</a> pred str 0))
        (<span class="local-name-binding">p2</span> (<a class="applied-name" href="general-1.html#find-in-string-by-predicate" title="general">find-in-string-by-predicate</a> (<a class="applied-name" href="general-1.html#negate" title="general">negate</a> pred) str p1)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> str) '())
         ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> p1 p2)
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 p1)
		  (<a class="applied-name" href="general-1.html#split-string-by-predicate-1" title="general">split-string-by-predicate-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str p2 strlen) pred)))
         ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> p1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> p2)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 p1)))
         ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> p1) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> p2))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> str))
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> '()))))


<a name="find-in-string"></a><div class="schemedoc-definition-comment">;; Search linearly for the character ch in the string str. 
;; An optional start postion start-post tells at which position to start the search (default is position 0).
;; Return the index of the first occurence of ch, or #f if it does not exist in str.
;; The index of the first character in a string is 0.
;; .internal-references "more general function" "find-in-string-by-predicate"
;; .form (find-in-string str ch [start-pos])
;; .parameter str The string in which to search.
;; .parameter ch The character we are searching for. 
;; .parameter start-pos The optional start-position of the search. Defaults to 0 (start of string). May also be boolean false.</div><a name="find-in-string"></a><span><a href="../general.html#find-in-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string str ch . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">start-pos</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list 0)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> start-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> start-pos))
      #f
     (<a class="applied-name" href="general-1.html#find-in-string-1" title="general">find-in-string-1</a> str ch start-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))))

<a name="find-in-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-1 str ch i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i lgt) #f)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)) i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-in-string-1" title="general">find-in-string-1</a> str ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))

<a name="find-in-string-from-end"></a><div class="schemedoc-definition-comment">;; Search linearly for the character ch in the string str, beginning from the rear end of str.
;; Return the index of the last occurence of ch, or #f if it does not exist in str.
;; The index of the first character in a string is 0.</div><a name="find-in-string-from-end"></a><span><a href="../general.html#find-in-string-from-end"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-from-end str ch)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))
  (<a class="applied-name" href="general-1.html#find-in-string-from-end-1" title="general">find-in-string-from-end-1</a> str ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) lgt)))

<a name="find-in-string-from-end-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-from-end-1 str ch i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i 0) #f)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)) i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-in-string-from-end-1" title="general">find-in-string-from-end-1</a> str ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> i 1) lgt))))

<a name="find-in-string-by-predicate"></a><div class="schemedoc-definition-comment">;; Find the first character in str that satisfies the char-predicate pred, and return index of that char.
;; The search starts at position start-pos.
;; If start-pos is a boolean false, this function always returns boolean false.
;; This is a linear search in the string, corresponding to find-in-list for lists.
;; .internal-references "similar function" "find-in-list"
;; .form (find-in-string-by-predicate pred str [start-pos])
;; .parameter pred A string predicate function
;; .parameter str The string in which to search
;; .parameter start-pos The optional start-position of the search. Defaults to 0 (start of string). May also be boolean false.</div><a name="find-in-string-by-predicate"></a><span><a href="../general.html#find-in-string-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-by-predicate pred str . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">start-pos</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list 0)))
  (<a class="applied-name" href="general-1.html#find-in-string-by-predicate-1" title="general">find-in-string-by-predicate-1</a> pred str start-pos start-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))))

<a name="find-in-string-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-by-predicate-1 pred str start-pos i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> start-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> start-pos)) #f)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i lgt) #f)
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)) i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-in-string-by-predicate-1" title="general">find-in-string-by-predicate-1</a> pred str start-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))

<a name="find-in-string-from-end-by-predicate"></a><div class="schemedoc-definition-comment">;; Find the last character in str that satisfies the char-predicate pred, and return index of that char.
;; The search starts at position start-pos.
;; If start-pos is a boolean false, this function always returns boolean false.
;; This is a rear end, linear search in the string, corresponding to find-in-list for lists.
;; .internal-references "similar function" "find-in-list-by-predicate"
;; .form (find-in-string-from-end-by-predicate pred str [start-pos])
;; .parameter pred A string predicate function
;; .parameter str The string in which to search
;; .parameter start-pos The optional start-position of the search. Defaults to the last position in str (end of string). May also be boolean false.</div><a name="find-in-string-from-end-by-predicate"></a><span><a href="../general.html#find-in-string-from-end-by-predicate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-from-end-by-predicate pred str . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">str-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
        (<span class="local-name-binding">start-pos</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> str-lgt 1))))
  (<a class="applied-name" href="general-1.html#find-in-string-from-end-by-predicate-1" title="general">find-in-string-from-end-by-predicate-1</a> pred str start-pos start-pos str-lgt)))

<a name="find-in-string-from-end-by-predicate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(find-in-string-from-end-by-predicate-1 pred str start-pos i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> start-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> start-pos)) #f)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i 0) #f)
        ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)) i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#find-in-string-from-end-by-predicate-1" title="general">find-in-string-from-end-by-predicate-1</a> pred str start-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> i 1) lgt))))



<a name="skip-chars-in-string"></a><div class="schemedoc-definition-comment">;; Starting from start-pos, skip characters in string from char-list.
;; Return the first index higher or equal to start-pos, which contains a character which is NOT in char-list.
;; This may be an index out of bound.
;; If start-pos is higher than the maximum legal string index, return start-post.
;; .parameter str The string on which this function works
;; .parameter char-list A list of characters
;; .parameter start-pos The position of the first character to consider. The index of the first character is 0.
;; .returns A string index, possibly out of bound (as described above). An integer.</div><a name="skip-chars-in-string"></a><span><a href="../general.html#skip-chars-in-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-chars-in-string str char-list start-pos)</span>
  (<a class="applied-name" href="general-1.html#skip-chars-in-string-1" title="general">skip-chars-in-string-1</a> str char-list start-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))

<a name="skip-chars-in-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(skip-chars-in-string-1 str char-list i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i) char-list))
          (<a class="applied-name" href="general-1.html#skip-chars-in-string-1" title="general">skip-chars-in-string-1</a> str char-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i) char-list)))
          i)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> i)))

<a name="string-merge"></a><div class="schemedoc-definition-comment">;; Merge str-list-1 with str-list-2, returning one string.
;; Strings from the first list are merged with the strings from the second list.
;; In case one list is shorter than the other, the strings from the longests lists
;; are concatenated and appended
;; .example (string-merge (list "aa" "bb" "cc") (list "XX" "YY")) =&gt; "aaXXbbYYcc"</div><a name="string-merge"></a><span><a href="../general.html#string-merge"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-merge str-list-1 str-list-2)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> str-list-1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> str-list-2))
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> str-list-2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> str-list-1))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a>
              (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> str-list-1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> str-list-2)
              (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> str-list-1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> str-list-2))))))

<a name="transliterate"></a><div class="schemedoc-definition-comment">;; In in-string, substitute each occurence of character ch with the string str.
;; As a special case, str may be the empty string, in which case occurrences of the character ch is eliminated from str.
;; .parameter in-string A string
;; .parameter ch The character to be translated. A Scheme character
;; .parameter str The string to substitute occurrences of ch 
;; .returns A new string with the desired substitutions</div><a name="transliterate"></a><span><a href="../general.html#transliterate"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(transliterate in-string ch str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str-factor</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) 1)))
  (<a class="applied-name" href="general-1.html#transliterate-1" title="general">transliterate-1</a> in-string 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> in-string) 
                  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> in-string) str-factor) #\space) 0
                  ch str)))

<a name="transliterate-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(transliterate-1 in-string n in-length
         out-string m 
         ch str)</span>
  <span class="comment">; n is the position in the input
; m is the positin in the output</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n in-length) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> out-string 0 m))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> n in-length)
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">in-char</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> in-string n)))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> in-char ch)
                  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="applied-name" href="general-1.html#copy-string-into!" title="general">copy-string-into!</a> out-string m str)
                         (<a class="applied-name" href="general-1.html#transliterate-1" title="general">transliterate-1</a> in-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> n 1) in-length out-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> m (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)) ch str))
                  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="applied-name" href="general-1.html#copy-string-into!" title="general">copy-string-into!</a> out-string m (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> in-char)) 
                         (<a class="applied-name" href="general-1.html#transliterate-1" title="general">transliterate-1</a> in-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> n 1) in-length out-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> m 1) ch str)))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (error "transliterate error")) ))

<a name="filter-string"></a><div class="schemedoc-definition-comment">;; Take away all characters in the string str that satisfy pred. 
;; Returns a string shorter than or equal to the length of str.
;; This function is a non-destructive function.
;; .parameter str The string to be filtered.
;; .parameter pred A string predicate function
;; .returns The filtered string. All characters in string, in the same order, that do not satisfy pred.
;; .misc An iterative function</div><a name="filter-string"></a><span><a href="../general.html#filter-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(filter-string pred str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">filter-string-1</span>
	   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">pred</span> <span class="local-name-binding">str-lgt</span> <span class="local-name-binding">str</span> <span class="local-name-binding">i</span> <span class="local-name-binding">result</span> <span class="local-name-binding">j</span>)
	     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i str-lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> result 0 j))
		   ((pred (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)) (filter-string-1 pred str-lgt str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) result j))
		   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
			   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> result j (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i))
			   (filter-string-1 pred str-lgt str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) result (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 1))))))))   
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">str-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
	  (<span class="local-name-binding">result</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> str-lgt)))
     (filter-string-1 pred str-lgt str 0 result 0))))


<a name="delete-string-portion"></a><div class="schemedoc-definition-comment">;; Delete the substring of length lgt from index i in the string str.
;; A non-destructive function which returns the result (a shorter string than the input).
;; i is supposed to be a valid index in str. If lgt is too long for str, we just delete to the end of str.
;; The first character is number 0.</div><a name="delete-string-portion"></a><span><a href="../general.html#delete-string-portion"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(delete-string-portion str i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">str-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
         (<span class="local-name-binding">prefix</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> i 0)))
         (<span class="local-name-binding">suffix</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX248" title="R5RS Scheme form">min</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i lgt) str-lgt) str-lgt)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> prefix suffix)))

<span class="comment">; -----------------------------------------------------------------------------</span><br />


<a name="replace-string"></a><div class="schemedoc-definition-comment">;; In str1 replace all occurences of str2 with str3 and return the resulting string.
;; str2 is not allowed to be empty.
;; A non-destructive function which leaves all input strings unaffected.</div><a name="replace-string"></a><span><a href="../general.html#replace-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(replace-string str1 str2 str3)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> str2))
      (<a class="applied-name" href="general-1.html#replace-string-1" title="general">replace-string-1</a> 0 str1 str2 str3)
      (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "replace-string: Cannot replace empty string in " str1))))

<a name="replace-string-1"></a><span class="comment">; A helping function of replace-string which replaces from a given index i.</span><br /><a name="replace-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(replace-string-1 i str1 str2 str3)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">match-index</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str1 i str2)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> match-index 
        (<a class="applied-name" href="general-1.html#replace-string-1" title="general">replace-string-1</a>
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> match-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str3))
          (<a class="applied-name" href="general-1.html#put-into-string" title="general">put-into-string</a> (<a class="applied-name" href="general-1.html#delete-string-portion" title="general">delete-string-portion</a> str1 match-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str2))  match-index str3)
          str2
          str3)
        str1)))


  

<a name="put-around-substring"></a><div class="schemedoc-definition-comment">;; Put pre-putin at pre-index, and post-putit at post-index in the string str.
;; Return the result. Str is not affected.
;; .pre-condition pre-index is less than post-index.</div><a name="put-around-substring"></a><span><a href="../general.html#put-around-substring"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-around-substring str pre-index pre-putin post-index post-putin)</span>
 (<a class="applied-name" href="general-1.html#put-into-string" title="general">put-into-string</a>
    (<a class="applied-name" href="general-1.html#put-into-string" title="general">put-into-string</a> str post-index post-putin)
                         pre-index pre-putin))

<a name="put-into-string"></a><div class="schemedoc-definition-comment">;; Before the character with index put in putin-str into str, and return the resulting,
;; extended string. I.e, make room in the resulting string for putin-str, and slide a suffix of str 
;; to the right. Str is left unchanged. The first character is number 0.</div><a name="put-into-string"></a><span><a href="../general.html#put-into-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-into-string str index putin-str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> putin-str)))))
   (<a class="applied-name" href="general-1.html#copy-string-into!" title="general">copy-string-into!</a> res 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 index))
   (<a class="applied-name" href="general-1.html#copy-string-into!" title="general">copy-string-into!</a> res index putin-str)
   (<a class="applied-name" href="general-1.html#copy-string-into!" title="general">copy-string-into!</a> res (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> putin-str)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))
   res))

<a name="embed-substring"></a><div class="schemedoc-definition-comment">;; Embed substring, as found in string, into embed-function.
;; A non-destructive function.
;; .parameter embed-function a function of one parameter, such as em, b.
;; .returns str with the first occurence of substring embedded into an activation of embed-function.
;; .example (embed-substring "LAML" "LAML is programmed in Scheme" em)</div><a name="embed-substring"></a><span><a href="../general.html#embed-substring"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(embed-substring substring str embed-function)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">i</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str 0 substring)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> i
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">pruned-str</span> (<a class="applied-name" href="general-1.html#delete-string-portion" title="general">delete-string-portion</a> str i (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> substring)))
	       (<span class="local-name-binding">new-str</span> (<a class="applied-name" href="general-1.html#put-into-string" title="general">put-into-string</a> pruned-str i (embed-function substring))))
          new-str)
        str)))

<a name="copy-string-into!"></a><div class="schemedoc-definition-comment">;; Copy source into target and overwrite a portion of target. 
;; Both target and source are strings, and i is an integer index.
;; The first char of source becomes chararter number i in the target string.
;; The first character in a string is number 0.
;; Target is mutated by this procedure.
;; If there is not enough room for source in target, only part of the source is copied into a suffix of target.</div><a name="copy-string-into!"></a><span><a href="../general.html#copy-string-into!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(copy-string-into! target i source)</span>
  (<a class="applied-name" href="general-1.html#copy-string-into-help!" title="general">copy-string-into-help!</a> target i (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> target) source 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> source)))

<a name="copy-string-into-help!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(copy-string-into-help! target i target-length source j source-length)</span>
  <span class="comment">; A helping operation, doing the real work, of copy-string-into!</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i target-length) target)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> j source-length) target)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> j source-length) 
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> target i (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> source j))
                     (<a class="applied-name" href="general-1.html#copy-string-into-help!" title="general">copy-string-into-help!</a> target (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 i) target-length source (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 j) source-length)))))

<a name="substring-index"></a><div class="schemedoc-definition-comment">;; Return the index of the first occurence of find-str in str.
;; The search starts at str-index.
;; The first character in str has index 0.
;; If find-str is not a substring of str, starting the search at str-index, #f is returned.</div><a name="substring-index"></a><span><a href="../general.html#substring-index"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(substring-index str str-index find-str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
       (<span class="local-name-binding">find-str-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> find-str)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> find-str)) str-index)  <span class="comment">; new 10.9.98</span><br />        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> str-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> str-length find-str-length)) #f)
        ((<a class="applied-name" href="general-1.html#substring-index-help" title="general">substring-index-help</a> str str-index str-length find-str 0 find-str-length) str-index)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 str-index) find-str)))))

<a name="substring-index-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(substring-index-help str str-index str-length find-str find-str-index find-str-length)</span>
  <span class="comment">; return whether find-str matches at postion str-index at str.
; I.e., at boolean results from this function
; str-length is the length of str.
; find-str-length is the length of the remaining part of find-str to match.
; find-str-index is the actual index ind find-str.
; str-index is the actua index of str.</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a>((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 find-str-length) #t)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> str-index str-length) #f)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str str-index) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> find-str find-str-index))
          (<a class="applied-name" href="general-1.html#substring-index-help" title="general">substring-index-help</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> str-index 1) str-length find-str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 find-str-index) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> find-str-length 1)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))


<a name="first-sentence-in-string"></a><div class="schemedoc-definition-comment">;; Return the first sentence in str (including a point).
;; The first sentence is running up to the first point followed by space or line termination.</div><a name="first-sentence-in-string"></a><span><a href="../general.html#first-sentence-in-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(first-sentence-in-string str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">point-index</span> (<a class="applied-name" href="general-1.html#first-sentence-split-point" title="general">first-sentence-split-point</a> str)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> point-index) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 point-index)) str)))

<a name="but-first-sentence-of-string"></a><div class="schemedoc-definition-comment">;; Return all but the first sentence in str.</div><a name="but-first-sentence-of-string"></a><span><a href="../general.html#but-first-sentence-of-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(but-first-sentence-of-string str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">point-index</span> (<a class="applied-name" href="general-1.html#first-sentence-split-point" title="general">first-sentence-split-point</a> str)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> point-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> point-index 2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)) "")))

<a name="first-sentence-split-point"></a><span class="comment">; Return the split point of the first sentence in str.
; If no split point can be located, return #f.</span><br /><a name="first-sentence-split-point"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(first-sentence-split-point str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">point-index-0</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str 0 ". "))
         (<span class="local-name-binding">point-index-1</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "." (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 10)))))
         (<span class="local-name-binding">point-index-2</span> (<a class="applied-name" href="general-1.html#substring-index" title="general">substring-index</a> str 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "." (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 13)))))
         (<span class="local-name-binding">point-index-min</span> (<a class="applied-name" href="general-1.html#min-special" title="general">min-special</a> point-index-0 point-index-1 point-index-2)))
    point-index-min))

<a name="min-special"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(min-special . numbers-or-nulls)</span>
  (<a class="applied-name" href="general-1.html#min-special-1" title="general">min-special-1</a> numbers-or-nulls #f))

<a name="min-special-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(min-special-1 numbers-or-nulls res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> numbers-or-nulls) res)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> res) (<a class="applied-name" href="general-1.html#min-special-1" title="general">min-special-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> numbers-or-nulls) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls) res))
            (<a class="applied-name" href="general-1.html#min-special-1" title="general">min-special-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> numbers-or-nulls) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> numbers-or-nulls) res))
            (<a class="applied-name" href="general-1.html#min-special-1" title="general">min-special-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> numbers-or-nulls) res))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#min-special-1" title="general">min-special-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> numbers-or-nulls) res))))

<a name="strip-initial-characters"></a><div class="schemedoc-definition-comment">;; Strip initial occurences of chars from char-list from string. Returns the empty string if given the empty string.
;; This function makes intermediate substrings, and as such it is not efficient.</div><a name="strip-initial-characters"></a><span><a href="../general.html#strip-initial-characters"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(strip-initial-characters char-list string)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> string) 0)
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> string 0) char-list)
          (<a class="applied-name" href="general-1.html#strip-initial-characters" title="general">strip-initial-characters</a> char-list (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> string 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> string)))
          string)))

<a name="strip-trailing-characters"></a><div class="schemedoc-definition-comment">;; Strip trailing occurences of the characters in char-list from string. </div><a name="strip-trailing-characters"></a><span><a href="../general.html#strip-trailing-characters"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(strip-trailing-characters char-list string)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">last-non-char-list-index</span> 
	   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">i</span>)
	     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i 0) i)
		   ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> string i) char-list)
                      (last-non-char-list-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> i 1)))
		   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> i)))) <span class="comment">; char i is not in char-list</span><br />         )
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">i</span> (last-non-char-list-index (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> string) 1)))
        )
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i 0)
	 ""
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> string 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1))))))


<a name="strip-initial-spaces"></a><div class="schemedoc-definition-comment">;; Strip all initial space characters and lineshifting characters from string.</div><a name="strip-initial-spaces"></a><span><a href="../general.html#strip-initial-spaces"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(strip-initial-spaces string)</span>
  (<a class="applied-name" href="general-1.html#strip-initial-characters" title="general">strip-initial-characters</a> 
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> #\space (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> 10) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> 13) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> 9) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> 12))
     string))
      

<a name="quote-string"></a><span class="comment">; con-par is in the html library file</span><br />


<a name="quote-string"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">quote-string</span> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> #\"))

<a name="string-it"></a><div class="schemedoc-definition-comment">;; embed the string x in double string quotes</div><a name="string-it"></a><span><a href="../general.html#string-it"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-it x)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> <a class="applied-name" href="general-1.html#quote-string" title="general">quote-string</a>  x <a class="applied-name" href="general-1.html#quote-string" title="general">quote-string</a>))

<a name="single-quote-string"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">single-quote-string</span> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> #\'))

<a name="string-it-single"></a><div class="schemedoc-definition-comment">;; embed the string x in single string quotes</div><a name="string-it-single"></a><span><a href="../general.html#string-it-single"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(string-it-single x)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> <a class="applied-name" href="general-1.html#single-quote-string" title="general">single-quote-string</a> x <a class="applied-name" href="general-1.html#single-quote-string" title="general">single-quote-string</a>))

<a name="exchange-chars-in-str!"></a><div class="schemedoc-definition-comment">;; Exchange destructively char n and m in str. First character is number 0.
;; Not a function, thus no return value.</div><a name="exchange-chars-in-str!"></a><span><a href="../general.html#exchange-chars-in-str!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(exchange-chars-in-str! str n m)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">remember-char</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str m)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str m (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str n))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str n remember-char)))

<a name="ensure-final-character"></a><div class="schemedoc-definition-comment">;; Ensure that the last character in str (a string) is ch (a char)</div><a name="ensure-final-character"></a><span><a href="../general.html#ensure-final-character"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-final-character str ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> lgt 0)
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> ch (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1))))
         str
         (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> str (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> ch)))))

<a name="repeat-string"></a><div class="schemedoc-definition-comment">;; Repeat the string str n times.
;; If n equals 0, return the empty string. 
;; Causes a fatal error if n is negative.</div><a name="repeat-string"></a><span><a href="../general.html#repeat-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(repeat-string str n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> n 0) (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "repeat-string with negative repeat count is not supported: " (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> n))))
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0) "")
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> str (<a class="applied-name" href="general-1.html#repeat-string" title="general">repeat-string</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))))

<a name="unescape-text"></a><div class="schemedoc-definition-comment">;; Unescape text with the escape character esc-char.
;; A pending escape character in text is just ignored.
;; Unescaping is the process of replacing a two-character text sequence ESC CHAR with CHAR.
;; .parameter text The input text string
;; .parameter esc-char The escape character. A Scheme char.
;; .example ab$c  -&gt; abc
;; .example $.xy  -&gt; .xy
;; .example $$xy  -&gt; $xy
;; .example $$$$x -&gt; $$x
;; .example xy$   -&gt; xy</div><a name="unescape-text"></a><span><a href="../general.html#unescape-text"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(unescape-text text esc-char)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">text-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> text)))
  (<a class="applied-name" href="general-1.html#unescape-1" title="general">unescape-1</a> text esc-char (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> text-lgt) 0 0 text-lgt #f)))

<a name="unescape-1"></a><span class="comment">; The procedure which does the real work of unescape-text.
; from-text is the original input text.
; esc-char is the escape character. 
; to-text is the resulting text, gradually mutated by this procedure.
; i is index in from-text and j is index in to-text
; from-text-length is the length of from-text.
; escape? is true if the next character in from-text is escaped. In that
; case, the next character will always appear in the to-text.</span><br /><a name="unescape-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(unescape-1 from-text esc-char to-text i j from-text-lgt escape?)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i from-text-lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> to-text 0 j))
       (escape?  <span class="comment">; previous char was escpae char.</span><br />          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> to-text j (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> from-text i)) 
          (<a class="applied-name" href="general-1.html#unescape-1" title="general">unescape-1</a> from-text esc-char to-text (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 1) from-text-lgt #f))
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> from-text i) esc-char)
          (<a class="applied-name" href="general-1.html#unescape-1" title="general">unescape-1</a> from-text esc-char to-text (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) j from-text-lgt #t))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> to-text j (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> from-text i)) 
          (<a class="applied-name" href="general-1.html#unescape-1" title="general">unescape-1</a> from-text esc-char to-text (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 1) from-text-lgt #f))))

<a name="rotate-string"></a><div class="schemedoc-definition-comment">;; Rotate the string str n positions.
;; The first character of the resulting string will be (string-ref str n), and so on iteratively and cyclic.</div><a name="rotate-string"></a><span><a href="../general.html#rotate-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(rotate-string str n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))
         (<span class="local-name-binding">n1</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX259" title="R5RS Scheme form">remainder</a> n lgt)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str n1 lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 n1))))


<div class="schemedoc-section-comment">;;; Functions that change letter case in string.
;;; Here comes a number of functions which changes the letter case of a string.
;;; In general we recommend use of the non-destructive versions of the functions, thus
;;; encouraging a clean, functional programming style. Due a difference between mutable and
;;; immutable strings, we have experienced problems with the destructive procedures in MzScheme.</div>


<span class="comment">;  Capitalizing characters and strings.</span><br />
<a name="capitalize-string"></a><div class="schemedoc-definition-comment">;; Mutate str to have an initial capital character. 
;; A destructive procedure. See capitalize-string-nd for a non-destructive variant.
;; .internal-references "non-destructive variant" "capitalize-string-nd"</div><a name="capitalize-string"></a><span><a href="../general.html#capitalize-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(capitalize-string str)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str 0 (<a class="applied-name" href="general-1.html#capitalize-char" title="general">capitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0)))
  str)

<a name="capitalize-string-nd"></a><div class="schemedoc-definition-comment">;; Return str with capital, initial character. 
;; A non-destructive variant of capitalize-string.
;; .internal-references "destructive variant" "capitalize-string"</div><a name="capitalize-string-nd"></a><span><a href="../general.html#capitalize-string-nd"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(capitalize-string-nd str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX395" title="R5RS Scheme form">string-copy</a> str)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> res 0 (<a class="applied-name" href="general-1.html#capitalize-char" title="general">capitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0)))
    res))

<a name="capitalize-char"></a><span class="comment">; if it makes sense, return the capital character corresponding to ch.
; else, just return ch</span><br /><a name="capitalize-char"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(capitalize-char ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">char-code</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX367" title="R5RS Scheme form">char-&gt;integer</a> ch)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#lower-case-letter-code?" title="general">lower-case-letter-code?</a> char-code)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">offset</span> (<a class="applied-name" href="general-1.html#small-capital-offset" title="general">small-capital-offset</a> char-code)))
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> char-code offset)))
        ch)))

<a name="lower-case-letter-code?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(lower-case-letter-code? n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n 97) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 122)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 230) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 248) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 229)))

<a name="small-capital-offset"></a><span class="comment">; in all cases, the distance between lower and upper case letters are -32 in the ASCII table</span><br /><a name="small-capital-offset"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(small-capital-offset n)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n 97) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 122)) -32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 230) -32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 248) -32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 229) -32)
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 0)))

<span class="comment">; -----------------------------------------------------------------------------
; Upcasing all characters in a string</span><br />
<a name="upcase-string"></a><div class="schemedoc-definition-comment">;; Upcase all characters in str. This function is non-destructive, i.e., it does not change the parameter str.</div><a name="upcase-string"></a><span><a href="../general.html#upcase-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(upcase-string str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) #\space)))
    (<a class="applied-name" href="general-1.html#upcase-string-help!" title="general">upcase-string-help!</a> str res 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))))

<a name="upcase-string-help!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(upcase-string-help! input output i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i lgt) output)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> output i (<a class="applied-name" href="general-1.html#capitalize-char" title="general">capitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> input i)))
              (<a class="applied-name" href="general-1.html#upcase-string-help!" title="general">upcase-string-help!</a> input output (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))

<span class="comment">; -----------------------------------------------------------------------------</span><br />
<span class="comment">; Downcasing all characters in a string</span><br />
<a name="downcase-string"></a><div class="schemedoc-definition-comment">;; Downcase all characters in str. This function is non-destructive, i.e., it does not change the parameter str.</div><a name="downcase-string"></a><span><a href="../general.html#downcase-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(downcase-string str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) #\space)))
    (<a class="applied-name" href="general-1.html#downcase-string-help!" title="general">downcase-string-help!</a> str res 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str))))

<a name="downcase-string-help!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(downcase-string-help! input output i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> i lgt) output)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> output i (<a class="applied-name" href="general-1.html#decapitalize-char" title="general">decapitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> input i)))
              (<a class="applied-name" href="general-1.html#downcase-string-help!" title="general">downcase-string-help!</a> input output (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))))

<span class="comment">; -----------------------------------------------------------------------------</span><br />
<span class="comment">; decapitalizing characters and strings.</span><br />
<a name="decapitalize-string"></a><div class="schemedoc-definition-comment">;; Mutate str to have lower case, initial character. 
;; A destructive procedure. See decapitalize-string-nd for a non-destructive variant.
;; .internal-references "non-destructive variant" "decapitalize-string-nd"</div><a name="decapitalize-string"></a><span><a href="../general.html#decapitalize-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(decapitalize-string str)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str 0 (<a class="applied-name" href="general-1.html#decapitalize-char" title="general">decapitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0)))
  str)

<a name="decapitalize-string-nd"></a><div class="schemedoc-definition-comment">;; Return str with lower case, initial character. 
;; A non-destructive variant of decapitalize-string.
;; .internal-references "destructive variant" "decapitalize-string"</div><a name="decapitalize-string-nd"></a><span><a href="../general.html#decapitalize-string-nd"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(decapitalize-string-nd str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX395" title="R5RS Scheme form">string-copy</a> str)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> res 0 (<a class="applied-name" href="general-1.html#decapitalize-char" title="general">decapitalize-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str 0)))
    res))

<a name="decapitalize-char"></a><span class="comment">; If it makes sense, return the lower case character corresponding to ch.
; else, just return ch.</span><br /><a name="decapitalize-char"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(decapitalize-char ch)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">char-code</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX367" title="R5RS Scheme form">char-&gt;integer</a> ch)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#upper-case-letter-code?" title="general">upper-case-letter-code?</a> char-code)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">offset</span> (<a class="applied-name" href="general-1.html#large-capital-offset" title="general">large-capital-offset</a> char-code)))
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX368" title="R5RS Scheme form">integer-&gt;char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> char-code offset)))
        ch)))

<a name="upper-case-letter-code?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(upper-case-letter-code? n)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n 65) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 90)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 198) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 216) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 197)))

<a name="large-capital-offset"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(large-capital-offset n)</span>
 <span class="comment">; in all cases, the distance between lower and upper case letters are -32 in the ASCII table</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> n 65) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> n 90)) 32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 198) 32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 216) 32)
       ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 197) 32)
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 0)))

<span class="comment">; ---------------------------------------------------------------------------------------------------</span><br />
<div class="schemedoc-section-comment">;;; Byte string functions.
;;; In this section we provide low-level functions that access binary data in strings. 
;;; This section has been added to LAML version 32.</div>
<a name="byte-string-to-integer"></a><div class="schemedoc-definition-comment">;; Given a byte string - most significant byte first - return the decimal integer which it represents.
;; .internal-references "Inverse function" "int10-to-binary"
;; The inverse function is int10-to-binary.
;; .parameter byte-str A string of bytes.
;; .returns An integer number
;; .pre-condition byte-str is not empty</div><a name="byte-string-to-integer"></a><span><a href="../general.html#byte-string-to-integer"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(byte-string-to-integer byte-str)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> byte-str)))
    (<a class="applied-name" href="general-1.html#byte-string-to-integer-1" title="general">byte-string-to-integer-1</a> byte-str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) 0 1)))

<a name="byte-string-to-integer-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(byte-string-to-integer-1 byte-str i res factor)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i 0)
      res
      (<a class="applied-name" href="general-1.html#byte-string-to-integer-1" title="general">byte-string-to-integer-1</a> byte-str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> i 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> res (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> (<a class="applied-name" href="general-1.html#as-number" title="general">as-number</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> byte-str i)) factor)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> factor 256))))

<a name="int10-to-binary"></a><div class="schemedoc-definition-comment">;; Convert a decimal integer n to a binary quantity, represented as string of length number-of-bytes.
;; If n is too large to be represented in number-of-bytes, an error occurs.
;; The inverse function is byte-string-to-integer.
;; .internal-references "Inverse function" "byte-string-to-integer"
;; .parameter n The integer to convert.
;; .parameter number-of-bytes  The desired number of bytes.
;; .result A string of bytes.</div><a name="int10-to-binary"></a><span><a href="../general.html#int10-to-binary"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(int10-to-binary n number-of-bytes)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">byte-list</span> (<a class="applied-name" href="general-1.html#binary-bytes-of-decimal-integer" title="general">binary-bytes-of-decimal-integer</a> n))
         (<span class="local-name-binding">lgt-byte-list</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> byte-list)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> lgt-byte-list number-of-bytes)
        (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "int10-to-binary: Number does not fit in" number-of-bytes "byte(s): " n)
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX394" title="R5RS Scheme form">list-&gt;string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a>
                         (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> number-of-bytes lgt-byte-list) (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> 0))    <span class="comment">; pad with initial zeros</span><br />                         byte-list)))))

<a name="binary-bytes-of-decimal-integer"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(binary-bytes-of-decimal-integer n)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#binary-bytes-of-decimal-integer-1" title="general">binary-bytes-of-decimal-integer-1</a> n)))

<a name="binary-bytes-of-decimal-integer-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(binary-bytes-of-decimal-integer-1 n)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">rem</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX259" title="R5RS Scheme form">remainder</a> n 256))
       (<span class="local-name-binding">rest</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> n 256)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> rest 0)
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> rem))
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> rem) (<a class="applied-name" href="general-1.html#binary-bytes-of-decimal-integer-1" title="general">binary-bytes-of-decimal-integer-1</a> rest)))))
         
    
<a name="make-char-2-hex"></a><div class="schemedoc-definition-comment">;; Make a character from two hex numbers
;; .parameter hx1 An integer number between 0 and 15
;; .parameter hx2 An integer number between 0 and 15
;; .returns A character</div><a name="make-char-2-hex"></a><span><a href="../general.html#make-char-2-hex"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-char-2-hex hx1 hx2 )</span>
  (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> hx1 16) hx2)))

<a name="make-byte-string-from-hex-2"></a><div class="schemedoc-definition-comment">;; Make a string, with single character, from two hex numbers. 
;; .parameter hx1 An decimal integer number between 0 and 15
;; .parameter hx2 An decimal integer number between 0 and 15
;; .returns A string of length one.</div><a name="make-byte-string-from-hex-2"></a><span><a href="../general.html#make-byte-string-from-hex-2"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-byte-string-from-hex-2 hx1 hx2)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX394" title="R5RS Scheme form">list-&gt;string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx1 hx2))))

<a name="make-byte-string-from-hex-4"></a><div class="schemedoc-definition-comment">;; Make a string, with two characters, from four hex numbers. 
;; .parameter hx1 An decimal integer number between 0 and 15
;; .parameter hx2 An decimal integer number between 0 and 15
;; .parameter hx3 An decimal integer number between 0 and 15
;; .parameter hx4 An decimal integer number between 0 and 15
;; .returns A string of length two</div><a name="make-byte-string-from-hex-4"></a><span><a href="../general.html#make-byte-string-from-hex-4"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-byte-string-from-hex-4 hx1 hx2 hx3 hx4)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX394" title="R5RS Scheme form">list-&gt;string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx1 hx2) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx3 hx4) )))

<a name="make-byte-string-from-hex-6"></a><div class="schemedoc-definition-comment">;; Make a string, with three characters, from two six numbers.
;; .parameter hx1 An decimal integer number between 0 and 15
;; .parameter hx2 An decimal integer number between 0 and 15
;; .parameter hx3 An decimal integer number between 0 and 15
;; .parameter hx4 An decimal integer number between 0 and 15
;; .parameter hx5 An decimal integer number between 0 and 15
;; .parameter hx6 An decimal integer number between 0 and 15
;; .returns A string of length three</div><a name="make-byte-string-from-hex-6"></a><span><a href="../general.html#make-byte-string-from-hex-6"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-byte-string-from-hex-6 hx1 hx2 hx3 hx4 hx5 hx6 )</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX394" title="R5RS Scheme form">list-&gt;string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx1 hx2) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx3 hx4) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx5 hx6))))

<a name="make-byte-string-from-hex-8"></a><div class="schemedoc-definition-comment">;; Make a string, with four characters, from eight hex numbers.
;; .parameter hx1 An decimal integer number between 0 and 15
;; .parameter hx2 An decimal integer number between 0 and 15
;; .parameter hx3 An decimal integer number between 0 and 15
;; .parameter hx4 An decimal integer number between 0 and 15
;; .parameter hx5 An decimal integer number between 0 and 15
;; .parameter hx6 An decimal integer number between 0 and 15
;; .parameter hx7 An decimal integer number between 0 and 15
;; .parameter hx8 An decimal integer number between 0 and 15
;; .returns A string of length four.</div><a name="make-byte-string-from-hex-8"></a><span><a href="../general.html#make-byte-string-from-hex-8"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-byte-string-from-hex-8 hx1 hx2 hx3 hx4 hx5 hx6 hx7 hx8)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX394" title="R5RS Scheme form">list-&gt;string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx1 hx2) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx3 hx4) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx5 hx6) (<a class="applied-name" href="general-1.html#make-char-2-hex" title="general">make-char-2-hex</a> hx7 hx8))))


<a name="binary-to-hex-string"></a><div class="schemedoc-definition-comment">;; Given byte-string, which is binary data.
;; Return a non-binary string, of hex codes, space separated (for human readbility). 
;; Each byte gives rise to two hex codes.
;; The inverse function of hex-to-binary-string.
;; .parameter byte-string A string of bytes (binary data).
;; .returns An ASCII text string with grouped, human readable hexadecimal ciffers.</div><a name="binary-to-hex-string"></a><span><a href="../general.html#binary-to-hex-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(binary-to-hex-string byte-string)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#binary-to-hex-string-1" title="general">binary-to-hex-string-1</a> byte-string 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> byte-string)))
        (<span class="local-name-binding">res-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> res)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> res-length 0) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> res 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> res-length 1)) res)  <span class="comment">; removes a trailing space</span><br /> )
)

<a name="binary-to-hex-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(binary-to-hex-string-1 byte-string i lgt)</span>  
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt)
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">byte</span> (<a class="applied-name" href="general-1.html#as-number" title="general">as-number</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> byte-string i)))
             (<span class="local-name-binding">low</span>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX259" title="R5RS Scheme form">remainder</a> byte 16))
             (<span class="local-name-binding">high</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX258" title="R5RS Scheme form">quotient</a> byte 16)))
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> 
          (<a class="applied-name" href="general-1.html#upcase-string" title="general">upcase-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> high 16)) (<a class="applied-name" href="general-1.html#upcase-string" title="general">upcase-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> low 16)) " "
          (<a class="applied-name" href="general-1.html#binary-to-hex-string-1" title="general">binary-to-hex-string-1</a> byte-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) lgt))) 
  )
)

<a name="hex-to-binary-string-relaxed"></a><div class="schemedoc-definition-comment">;; Given a human readable hex string, as produced by the sibling function called binary-to-hex-string.
;; Groups of two hex ciffers must be separated by one or more spaces or CRs.
;; Return the corresponding binary string.
;; The inverse function of binary-to-hex-string.
;; .parameter byte-string A string of bytes (binary data).
;; .returns An ASCII text string with grouped, human readable hexadecimal ciffers.</div><a name="hex-to-binary-string-relaxed"></a><span><a href="../general.html#hex-to-binary-string-relaxed"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(hex-to-binary-string-relaxed hex-string)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> hex-string) 0)
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">hex-string-extended</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> hex-string " ")))
        (<a class="applied-name" href="general-1.html#hex-to-binary-string-relaxed-1" title="general">hex-to-binary-string-relaxed-1</a> hex-string-extended 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> hex-string-extended)))))


<a name="hex-to-binary-string-relaxed-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(hex-to-binary-string-relaxed-1 hex-string i lgt)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">j</span> (<a class="applied-name" href="general-1.html#find-in-string-by-predicate" title="general">find-in-string-by-predicate</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">c</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX339" title="R5RS Scheme form">memv</a> (<a class="applied-name" href="general-1.html#as-number" title="general">as-number</a> c) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> 9 10 13 32)))) hex-string i)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> j))
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">high-hex</span> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> hex-string j))) <span class="comment">; "1" .. "f"      </span><br />             (<span class="local-name-binding">low-hex</span>  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> hex-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 1)))) <span class="comment">; "1" .. "f"</span><br />             (<span class="local-name-binding">high-decimal</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX294" title="R5RS Scheme form">string-&gt;number</a> high-hex 16))
             (<span class="local-name-binding">low-decimal</span>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX294" title="R5RS Scheme form">string-&gt;number</a> low-hex 16) )
             )
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> 16 high-decimal) low-decimal))) 
                       (<a class="applied-name" href="general-1.html#hex-to-binary-string-relaxed-1" title="general">hex-to-binary-string-relaxed-1</a> hex-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> j 2) lgt))))))


<a name="hex-to-binary-string"></a><div class="schemedoc-definition-comment">;; Given a human readable hex string, as produced by the sibling function called binary-to-hex-string.
;; Groups of two hex ciffers must be separated by exactly one space.
;; Return the corresponding binary string.
;; The inverse function of binary-to-hex-string.
;; This function is like hex-to-binary-string relaxed, but with a stronger precondition.
;; .parameter byte-string A string of bytes (binary data).
;; .returns An ASCII text string with grouped, human readable hexadecimal ciffers.</div><a name="hex-to-binary-string"></a><span><a href="../general.html#hex-to-binary-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(hex-to-binary-string hex-string)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> hex-string) 0)
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">hex-string-extended</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> hex-string " ")))
        (<a class="applied-name" href="general-1.html#hex-to-binary-string-1" title="general">hex-to-binary-string-1</a> hex-string-extended 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> hex-string-extended)))))

<a name="hex-to-binary-string-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(hex-to-binary-string-1 hex-string i lgt)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> i lgt)
      ""
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">high-hex</span> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> hex-string i))) <span class="comment">; "1" .. "f"      </span><br />             (<span class="local-name-binding">low-hex</span>  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> hex-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1)))) <span class="comment">; "1" .. "f"</span><br />             (<span class="local-name-binding">high-decimal</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX294" title="R5RS Scheme form">string-&gt;number</a> high-hex 16))
             (<span class="local-name-binding">low-decimal</span>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX294" title="R5RS Scheme form">string-&gt;number</a> low-hex 16) )
             )
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> (<a class="applied-name" href="general-1.html#as-char" title="general">as-char</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> 16 high-decimal) low-decimal))) 
                       (<a class="applied-name" href="general-1.html#hex-to-binary-string-1" title="general">hex-to-binary-string-1</a> hex-string (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 3) lgt)))))

<span class="comment">; ---------------------------------------------------------------------------------------------------------------</span><br />


<div class="schemedoc-section-comment">;;; Message displaying and error handling procedures.
;;; Most message or error functions accept a list of messages which are string-converted and
;;; space separated before outputted.</div>
<a name="laml-aggregate-messages"></a><span class="comment">; Aggreate the messages in list to a single message-string.
; Applies as-string before space separated concatenation.</span><br /><a name="laml-aggregate-messages"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(laml-aggregate-messages message-list)</span>
 (<a class="applied-name" href="general-1.html#string-merge" title="general">string-merge</a> 
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> message-list)
  (<a class="applied-name" href="general-1.html#make-list" title="general">make-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> message-list) 1) " ")))

<a name="display-warning"></a><div class="schemedoc-definition-comment">;; Display a warning message line on standard output via the Scheme display function.
;; This is not a fatal error</div><a name="display-warning"></a><span><a href="../general.html#display-warning"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(display-warning . messages)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX461" title="R5RS Scheme form">display</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Warning: " (<a class="applied-name" href="general-1.html#laml-aggregate-messages" title="general">laml-aggregate-messages</a> messages))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX463" title="R5RS Scheme form">newline</a>))

<a name="display-error"></a><div class="schemedoc-definition-comment">;; Display an error message - in terms of messages - and stop the program. 
;; This is a fatal event.</div><a name="display-error"></a><span><a href="../general.html#display-error"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(display-error . messages)</span>
  (error (<a class="applied-name" href="general-1.html#laml-aggregate-messages" title="general">laml-aggregate-messages</a> messages)))

<a name="display-message"></a><div class="schemedoc-definition-comment">;; Display messages on standard output.
;; Not a warning, and not fatal by any means.</div><a name="display-message"></a><span><a href="../general.html#display-message"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(display-message . messages)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX461" title="R5RS Scheme form">display</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#laml-aggregate-messages" title="general">laml-aggregate-messages</a> messages))) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX463" title="R5RS Scheme form">newline</a>)))


<a name="laml-error"></a><div class="schemedoc-definition-comment">;; Stop the program with messages. 
;; This procedures takes an arbitrary number of parameters, which are string converted and string-appended
;; to the final error message.</div><a name="laml-error"></a><span><a href="../general.html#laml-error"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(laml-error . messages)</span>
  (error (<a class="applied-name" href="general-1.html#laml-aggregate-messages" title="general">laml-aggregate-messages</a> messages)))


<a name="errors-among-conditions"></a><div class="schemedoc-definition-comment">;; Return a list of error message strings for those conditions err-condition-message-list that are true.
;; The function returns #f in case all error conditions are false. 
;; err-condition-message-list is a property list (of even length) of error-condition error message pairs.
;; For each condition and message, this function checks the condition and returns the error message if the condition fails.
;; .parameter err-condition-message-list a property list of the form cond-1 mes-1 ... cond-n mes-n.
;; .returns A non-empty error message string, or #f.</div><a name="errors-among-conditions"></a><span><a href="../general.html#errors-among-conditions"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(errors-among-conditions . err-condition-message-list)</span>
  (<a class="applied-name" href="general-1.html#errors-among-conditions-1" title="general">errors-among-conditions-1</a> err-condition-message-list #f '()))

<a name="errors-among-conditions-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(errors-among-conditions-1 err-condition-message-list errors-found accumulated-error-messages)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> err-condition-message-list) (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> errors-found (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> accumulated-error-messages) #f))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">error-condition</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> err-condition-message-list))
                    (<span class="local-name-binding">error-message</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cadr</a> err-condition-message-list)))
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> error-condition 
                    (<a class="applied-name" href="general-1.html#errors-among-conditions-1" title="general">errors-among-conditions-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> err-condition-message-list) #t (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> error-message accumulated-error-messages))
                    (<a class="applied-name" href="general-1.html#errors-among-conditions-1" title="general">errors-among-conditions-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX325" title="R5RS Scheme form">cddr</a> err-condition-message-list) errors-found accumulated-error-messages))))
  ))




<div class="schemedoc-section-comment">;;; File name, file path and URL functions.
;;; File paths are represented as strings in LAML. 
;;; As a convention, a non-empty relative file path always ends in a forward slash '/'.
;;; The empty string represents the empty relative file path.
;;; An absolute file path is recognized in both unix form (for instance "/x/y/") and Windows form (for instance "c:\x\").
;;; Internally in LAML, we work with unix representation of file paths (using forward slashes).</div>

<a name="file-name-sans-extension"></a><div class="schemedoc-definition-comment">;; Return the filename component sans the final extension.
;; The extension, in a file name, is the part that follows the last `.'.
;; If no dot character is found the function returns file-name.
;; .misc This function does not work well if we use '.' as part of directory names.</div><a name="file-name-sans-extension"></a><span><a href="../general.html#file-name-sans-extension"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-name-sans-extension file-name)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">extension-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\.)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> extension-pos
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> file-name 0 extension-pos)
        file-name)))

<a name="file-name-proper"></a><div class="schemedoc-definition-comment">;; Return the part of file-name without extension and without an initial path.
;; Is also applicable on relative/absolute file path, and on URLs.
;; Works as expected even there are dots in the initial path.</div><a name="file-name-proper"></a><span><a href="../general.html#file-name-proper"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-name-proper file-name)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">extension-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\.))
        (<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\/))
        (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\\))
        (<span class="local-name-binding">max-slash-pos</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> forward-slash-pos backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> forward-slash-pos backward-slash-pos))
                             (forward-slash-pos forward-slash-pos)
                             (backward-slash-pos backward-slash-pos)
                             (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> -1)))
        (<span class="local-name-binding">extension-pos-1</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> extension-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> extension-pos max-slash-pos)) extension-pos #f))
      )
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a>
      file-name
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> max-slash-pos 1)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> extension-pos-1 extension-pos-1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> file-name)))))

<a name="file-name-proper-and-extension"></a><div class="schemedoc-definition-comment">;; Return the part of file-name, with a possible extension, but without an initial path.
;; Is also applicable on relative/absolute file path, and on URLs.</div><a name="file-name-proper-and-extension"></a><span><a href="../general.html#file-name-proper-and-extension"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-name-proper-and-extension file-path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">fnp</span> (<a class="applied-name" href="general-1.html#file-name-proper" title="general">file-name-proper</a> file-path))
        (<span class="local-name-binding">fne</span> (<a class="applied-name" href="general-1.html#file-name-extension" title="general">file-name-extension</a> file-path)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> fne)
        fnp
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> fnp "." fne))))


<a name="file-name-extension"></a><div class="schemedoc-definition-comment">;; Return the extension of file-name.
;; Is also applicable on relative/absolute file path, and on URLs.
;; If there is no extension, return the empty string.
;; The extension, in a file name, is the part that follows the last `.'.
;; This function handles dots in the initial path properly.</div><a name="file-name-extension"></a><span><a href="../general.html#file-name-extension"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-name-extension file-name)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">extension-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\.))
       (<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\/))
       (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-name #\\)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> extension-pos forward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> extension-pos forward-slash-pos))
            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> file-name (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> extension-pos 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> file-name)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> extension-pos forward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> extension-pos forward-slash-pos))
            "")
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> extension-pos backward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> extension-pos backward-slash-pos))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> file-name (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> extension-pos 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> file-name)))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> extension-pos backward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> extension-pos backward-slash-pos))
             "")
        (extension-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> file-name (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> extension-pos 1) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> file-name)))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> ""))))


<a name="file-name-initial-path"></a><div class="schemedoc-definition-comment">;; Return the initial path of file-path. 
;; The initial path of a file path is the prefix of the file path, without the proper file name
;; and without the extension. The initial path ends in a forward or backward slash, or it is empty.
;; Can also be applied on both absolute and relative file paths, and on absolute and relative URLs. </div><a name="file-name-initial-path"></a><span><a href="../general.html#file-name-initial-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-name-initial-path file-path)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">extension-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-path #\.))
       (<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-path #\/))
       (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> file-path #\\)))
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> 
    file-path
    0
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> forward-slash-pos backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> forward-slash-pos backward-slash-pos)))
	  (forward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 forward-slash-pos))
	  (backward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 backward-slash-pos))
	  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> 0))
  )))

<a name="absolute-file-path?"></a><div class="schemedoc-definition-comment">;; Return whether x represents an absolute path to a file. Works on both Unix and Windows.
;; .parameter x A file path (a string)</div><a name="absolute-file-path?"></a><span><a href="../general.html#absolute-file-path?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(absolute-file-path? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> x #\/))
        (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> x #\\))
        (<span class="local-name-binding">colon-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> x #\:)))
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 forward-slash-pos))
         (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> colon-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 colon-pos)
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a>
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 backward-slash-pos))
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 forward-slash-pos)))))))


<a name="absolute-url?"></a><div class="schemedoc-definition-comment">;; Does the string x represent an absolute URL.</div><a name="absolute-url?"></a><span><a href="../general.html#absolute-url?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(absolute-url? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "http://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "https://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "file://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "prospero://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "wais://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "telnet://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "gopher://")
      (<a class="applied-name" href="general-1.html#looking-at-substring?" title="general">looking-at-substring?</a> x 0 "news:")))

<a name="relative-url?"></a><div class="schemedoc-definition-comment">;; Does the string x represen a relative URL. 
;; .misc Experimental definition.</div><a name="relative-url?"></a><span><a href="../general.html#relative-url?"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(relative-url? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="applied-name" href="general-1.html#absolute-url?" title="general">absolute-url?</a> x)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="applied-name" href="general-1.html#absolute-file-path?" title="general">absolute-file-path?</a> x))))

<a name="parent-directory"></a><div class="schemedoc-definition-comment">;; Return the name of the parent directory of dir (a string), or #f if dir is the root directory. Also return #f in case dir is the value #f.</div><a name="parent-directory"></a><span><a href="../general.html#parent-directory"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(parent-directory dir)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> dir) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> dir))
     #f
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">dir1</span> (<a class="applied-name" href="general-1.html#ensure-final-character" title="general">ensure-final-character</a> dir #\/))
	    (<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir1))
	    (<span class="local-name-binding">dir2</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir1 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) 0)))	<span class="comment">; dir without ending slash</span><br />	    (<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> dir2 #\/))
	    (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string-from-end" title="general">find-in-string-from-end</a> dir2 #\\)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> forward-slash-pos backward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> forward-slash-pos backward-slash-pos))
	      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir2 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 forward-slash-pos)))
	     ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> forward-slash-pos backward-slash-pos (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> backward-slash-pos forward-slash-pos))
	      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir2 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 backward-slash-pos)))
	     (forward-slash-pos
	      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir2 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 forward-slash-pos)))
	     (backward-slash-pos
	      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir2 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 backward-slash-pos)))
	     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))))

<a name="directory-leave-name"></a><div class="schemedoc-definition-comment">;; Return the name of the leave directory of the directory dir.
;; In case dir is the absolute root, the value #f, or the empty directory string, this function returns #f.
;; .parameter dir A relative or absolute directory path (ends with '/').
;; .example (directory-leave-name "xxx/yyy/") =&gt; "yyy"</div><a name="directory-leave-name"></a><span><a href="../general.html#directory-leave-name"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(directory-leave-name dir)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX305" title="R5RS Scheme form">boolean?</a> dir) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> dir))
     #f 
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">dir1</span> (<a class="applied-name" href="general-1.html#ensure-final-character" title="general">ensure-final-character</a> dir #\/))
	    (<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir1))
	    (<span class="local-name-binding">dir2</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir1 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> lgt 1) 0)))	<span class="comment">; dir without ending slash</span><br />	    (<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#file-name-proper" title="general">file-name-proper</a> dir2)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> res) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> #\: (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> dir2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir2) 1))))
	   #f
	   res))))

<a name="directory-level-difference"></a><div class="schemedoc-definition-comment">;; Return the number of directory levels in between dir1 and dir2.
;; If dir1 is not a subdirectory of dir2, or dir2 is not a subdirectory of dir1 return #f.
;; .example (directory-level-difference "/x/x/z/v/" "/x/x/") = 2
;; .example (directory-level-difference "/x/x/" "/x/x/z/v/") = -2</div><a name="directory-level-difference"></a><span><a href="../general.html#directory-level-difference"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(directory-level-difference dir1 dir2)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">dir1-lc</span> (<a class="applied-name" href="general-1.html#downcase-string" title="general">downcase-string</a> dir1))
       (<span class="local-name-binding">dir2-lc</span> (<a class="applied-name" href="general-1.html#downcase-string" title="general">downcase-string</a> dir2)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">res1</span> (<a class="applied-name" href="general-1.html#directory-level-difference-1" title="general">directory-level-difference-1</a> dir1-lc dir2-lc 0))
        (<span class="local-name-binding">res2</span> (<a class="applied-name" href="general-1.html#directory-level-difference-1" title="general">directory-level-difference-1</a> dir2-lc dir1-lc 0)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> res1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> res1)) res1)
          ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> res2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> res2)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> res2))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))))

<a name="directory-level-difference-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(directory-level-difference-1 dir1 dir2 n)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">parent-dir-1</span> (<a class="applied-name" href="general-1.html#parent-directory" title="general">parent-directory</a> dir1)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> dir1 dir2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> dir1 dir2)) n)
         ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> parent-dir-1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX374" title="R5RS Scheme form">string?</a> parent-dir-1)) (<a class="applied-name" href="general-1.html#directory-level-difference-1" title="general">directory-level-difference-1</a> parent-dir-1 dir2 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> n 1)))
         ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> parent-dir-1) #f))))

<a name="relative-path-to-path-list"></a><div class="schemedoc-definition-comment">;; Given a relative file path, return a list of path constituents.
;; .pre-condition dir is not an absolute file path.
;; This function supports both forward and backward slashes as separator between directory levels (both unix and windows conventions).
;; .example (relative-path-to-path-list "xxx/yyy/zzz/") = ("xxx" "yyy" "zzz")
;; .example (relative-path-to-path-list "xxx/yyy/zzz") = ("xxx" "yyy" "zzz")
;; .example (relative-path-to-path-list "xxx") = ("xxx")</div><a name="relative-path-to-path-list"></a><span><a href="../general.html#relative-path-to-path-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(relative-path-to-path-list dir)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> dir)
     '()
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">dir1</span> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> dir (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir) 1)) #\/) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> dir (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir) 1)) #\\))
		      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir) 1))
		      dir))		<span class="comment">; no trailing slash</span><br />	    (<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> dir1))
	    (<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> dir1 #\/))
            (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> dir1 #\\))
            (<span class="local-name-binding">slash-pos</span> 
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> forward-slash-pos backward-slash-pos)
                       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX248" title="R5RS Scheme form">min</a> forward-slash-pos backward-slash-pos))
                    (forward-slash-pos forward-slash-pos)
                    (backward-slash-pos backward-slash-pos)
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> #f)))
           )
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> slash-pos
	   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir1 0 slash-pos)
		 (<a class="applied-name" href="general-1.html#relative-path-to-path-list" title="general">relative-path-to-path-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> dir1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 slash-pos) lgt)))
	   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> dir1)))))

<a name="path-list-to-relative-path"></a><div class="schemedoc-definition-comment">;; Return the relative path formed by the element of path-list.
;; The reverse function of relative-path-to-path-list.</div><a name="path-list-to-relative-path"></a><span><a href="../general.html#path-list-to-relative-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(path-list-to-relative-path path-list)</span>
  (<a class="applied-name" href="general-1.html#ensure-final-character" title="general">ensure-final-character</a> (<a class="applied-name" href="general-1.html#list-to-string" title="general">list-to-string</a> path-list "/")  #\/))

<a name="ensure-directory-existence!"></a><div class="schemedoc-definition-comment">;; Ensure that the directory with path (string-append prefix-dir dir) exists.
;; If necessary, create dir in prefix-dir.
;; .pre-condition prefix-dir should be normalized (using for instance normalize-file-path) before calling this function.
;; .parameter prefix-dir An absolute directory path.
;; .parameter dir A single directory name</div><a name="ensure-directory-existence!"></a><span><a href="../general.html#ensure-directory-existence!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-directory-existence! prefix-dir dir)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (directory-exists? (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> prefix-dir dir)))
      (make-directory-in-directory prefix-dir dir)))

<a name="ensure-directory-path-existence!"></a><div class="schemedoc-definition-comment">;; Ensure that the relative path, as represented by the parameter path, exists in prefix-dir.
;; This procedure creates the necessary directories in prefix-dir.
;; .pre-condition Both prefix-dir and path should be normalized (using for instance normalize-file-path) before calling this function.
;; .parameter prefix-dir An absolute directory path.
;; .parameter path A relative file path.</div><a name="ensure-directory-path-existence!"></a><span><a href="../general.html#ensure-directory-path-existence!"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-directory-path-existence! prefix-dir path)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">path-list</span> (<a class="applied-name" href="general-1.html#relative-path-to-path-list" title="general">relative-path-to-path-list</a> path)))
   (<a class="applied-name" href="general-1.html#ensure-directory-path-existence-1!" title="general">ensure-directory-path-existence-1!</a> prefix-dir path-list)))

<a name="ensure-directory-path-existence-1!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-directory-path-existence-1! prefix-dir path-list)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-list))
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">first-path</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list)))
         (<a class="applied-name" href="general-1.html#ensure-directory-existence!" title="general">ensure-directory-existence!</a> prefix-dir first-path)
         (<a class="applied-name" href="general-1.html#ensure-directory-path-existence-1!" title="general">ensure-directory-path-existence-1!</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> prefix-dir first-path "/") (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list)))))

<a name="ensure-non-existing-file-in-dir"></a><div class="schemedoc-definition-comment">;; Ensure that the file f (proper name and extension) is non-existing in the directory d.
;; If not, add a numeric suffix to the proper name of f.
;; Return the possibly modified file name (proper name and extension).</div><a name="ensure-non-existing-file-in-dir"></a><span><a href="../general.html#ensure-non-existing-file-in-dir"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-non-existing-file-in-dir f d)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (file-exists? (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> d f)))
     f
     (<a class="applied-name" href="general-1.html#ensure-non-existing-file-in-dir-1" title="general">ensure-non-existing-file-in-dir-1</a> f d 1)))

<a name="ensure-non-existing-file-in-dir-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(ensure-non-existing-file-in-dir-1 f d i)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">pf</span> (<a class="applied-name" href="general-1.html#file-name-proper" title="general">file-name-proper</a> f))
        (<span class="local-name-binding">ef</span> (<a class="applied-name" href="general-1.html#file-name-extension" title="general">file-name-extension</a> f))
        (<span class="local-name-binding">nm</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> pf "-" (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> i) "." ef))
        (<span class="local-name-binding">path</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> d nm))
      )
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (file-exists? path))
     nm
     (<a class="applied-name" href="general-1.html#ensure-non-existing-file-in-dir-1" title="general">ensure-non-existing-file-in-dir-1</a> f d (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1)))))

<a name="normalize-file-path"></a><div class="schemedoc-definition-comment">;; Normalizes the abolute or relative file path by removal of redundant ".." levels.
;; .parameter path An absolute or relative file path.
;; .returns A normalized absolute or relative file path. Always slash terminated.</div><a name="normalize-file-path"></a><span><a href="../general.html#normalize-file-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(normalize-file-path path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="applied-name" href="general-1.html#absolute-file-path?" title="general">absolute-file-path?</a> path) (<a class="applied-name" href="general-1.html#normalize-absolute-file-path" title="general">normalize-absolute-file-path</a> path))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#normalize-relative-file-path" title="general">normalize-relative-file-path</a> path))))

<a name="normalize-relative-file-path"></a><div class="schemedoc-definition-comment">;; Normalizes the relative file path for redundant ".." levels.
;; Does always return a forward slash terminated relative path, or and empty path (the emtpy string).
;; Does never lead to a fatal error.
;; .parameter path A relative file path. May be empty (the empty string).
;; .returns The normalized relative path (a string).</div><a name="normalize-relative-file-path"></a><span><a href="../general.html#normalize-relative-file-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(normalize-relative-file-path path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">path-list</span> (<a class="applied-name" href="general-1.html#relative-path-to-path-list" title="general">relative-path-to-path-list</a> path)))
     (<a class="applied-name" href="general-1.html#normalize-relative-file-path-1" title="general">normalize-relative-file-path-1</a> path-list '())))

<a name="normalize-relative-file-path-1"></a><span class="comment">; path-list is the relative path as a list.
; path-stack is a stack of already seen directories.</span><br /><a name="normalize-relative-file-path-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(normalize-relative-file-path-1 path-list path-stack)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-list)                           
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-stack)
                ""
                (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> (<a class="applied-name" href="general-1.html#list-to-string" title="general">list-to-string</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> path-stack) "/") "/")))
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-stack)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-stack))))   
            (<a class="applied-name" href="general-1.html#normalize-relative-file-path-1" title="general">normalize-relative-file-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-stack)))                          
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-stack)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-stack)))    
            (<a class="applied-name" href="general-1.html#normalize-relative-file-path-1" title="general">normalize-relative-file-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list)  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> ".." path-stack)))                   
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-stack))                                         
            (<a class="applied-name" href="general-1.html#normalize-relative-file-path-1" title="general">normalize-relative-file-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> ".." path-stack)))                    
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                                                                           
            (<a class="applied-name" href="general-1.html#normalize-relative-file-path-1" title="general">normalize-relative-file-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list) path-stack)))         
  )
)

<a name="normalize-absolute-file-path"></a><div class="schemedoc-definition-comment">;; Normalizes the absolute file path for redundant ".." levels.
;; May result in a fatal error in cases where we try to exit through the root level via "..".
;; Returns a forward slash terminated absolute path.
;; .parameter path An absoulte file path.
;; .pre-condition path is an absolute file path.
;; .returns The normalized absolute path (a string).</div><a name="normalize-absolute-file-path"></a><span><a href="../general.html#normalize-absolute-file-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(normalize-absolute-file-path abs-path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">prefix</span> (<a class="applied-name" href="general-1.html#prefix-part-of-absolute-path" title="general">prefix-part-of-absolute-path</a> abs-path))
         (<span class="local-name-binding">suffix</span> (<a class="applied-name" href="general-1.html#relative-part-of-absolute-path" title="general">relative-part-of-absolute-path</a> abs-path))
         (<span class="local-name-binding">res</span> (<a class="applied-name" href="general-1.html#normalize-relative-file-path" title="general">normalize-relative-file-path</a> suffix)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX239" title="R5RS Scheme form">&gt;=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> res) 2) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> ".." (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> res 0 2)))
        (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "normalize-absolute-file-path: Not possible to normalize the absolute file path" abs-path)
        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> prefix res))))


<a name="relative-part-of-absolute-path"></a><div class="schemedoc-definition-comment">;; Return the suffix part of the absolute file path  (the part following the initial "/" for instance).
;; .pre-condition abs-path is an absolute file path.</div><a name="relative-part-of-absolute-path"></a><span><a href="../general.html#relative-part-of-absolute-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(relative-part-of-absolute-path abs-path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\/))
        (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\\))
        (<span class="local-name-binding">colon-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\:))
        (<span class="local-name-binding">abs-path-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> abs-path))
       )
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 forward-slash-pos))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> abs-path 1 abs-path-length))
          ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> colon-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 colon-pos)
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a>
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 backward-slash-pos))
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 forward-slash-pos))))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> abs-path 3 abs-path-length))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "relative-part-of-absolute-path: The path" abs-path "is not an absolute file path.")))))


<a name="prefix-part-of-absolute-path"></a><div class="schemedoc-definition-comment">;; Return the prefix part of the absolute file path (the "/" or the "c:\" for instance).
;; .pre-condition abs-path is an absolute file path.</div><a name="prefix-part-of-absolute-path"></a><span><a href="../general.html#prefix-part-of-absolute-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(prefix-part-of-absolute-path abs-path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\/))
        (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\\))
        (<span class="local-name-binding">colon-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\:))
        (<span class="local-name-binding">abs-path-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> abs-path))
       )
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 forward-slash-pos))
             "/")
          ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> colon-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 colon-pos)
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a>
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 backward-slash-pos))
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 forward-slash-pos))))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> abs-path 0 3))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "prefix-part-of-absolute-path: The path" abs-path "is not an absolute file path.")))))

<a name="but-prefix-part-of-absolute-path"></a><div class="schemedoc-definition-comment">;; Return the complementary part of the absolute file path relative to (prefix-part-of-absolute-path abs-path).
;; Notice that (string-append (prefix-part-of-absolute-path abs-path) (but-prefix-part-of-absolute-path abs-path)) equals abs-path.
;; .pre-condition abs-path is an absolute file path.
;; .returns The largest possible relative file path taken from abs-path.</div><a name="but-prefix-part-of-absolute-path"></a><span><a href="../general.html#but-prefix-part-of-absolute-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(but-prefix-part-of-absolute-path abs-path)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">forward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\/))
        (<span class="local-name-binding">backward-slash-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\\))
        (<span class="local-name-binding">colon-pos</span> (<a class="applied-name" href="general-1.html#find-in-string" title="general">find-in-string</a> abs-path #\:))
        (<span class="local-name-binding">abs-path-length</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> abs-path))
        (<span class="local-name-binding">abs-path-lgt</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> abs-path))
       )
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 forward-slash-pos))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> abs-path 1 abs-path-lgt))
          ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> colon-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 1 colon-pos)
                (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a>
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> backward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 backward-slash-pos))
                 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> forward-slash-pos) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 2 forward-slash-pos))))
             (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> abs-path 3 abs-path-lgt))
          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "but-prefix-part-of-absolute-path: The path" abs-path "is not an absolute file path.")))))
            

<a name="inverse-return-path"></a><div class="schemedoc-definition-comment">;; Return the inverse file path of path, as taken relative to dir.
;; Given dir as the current directory. If we follow path, and then follow the inverse return path (the result of this function) we are back in dir.
;; .parameter path A relative file path from dir
;; .parameter dir A directory, identified by an absolute file path
;; .returns A relative file path.</div><a name="inverse-return-path"></a><span><a href="../general.html#inverse-return-path"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(inverse-return-path path dir)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="applied-name" href="general-1.html#empty-string?" title="general">empty-string?</a> path)
     ""
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">path-list</span> (<a class="applied-name" href="general-1.html#relative-path-to-path-list" title="general">relative-path-to-path-list</a> path))
           (<span class="local-name-binding">leave-of-dir</span> (<a class="applied-name" href="general-1.html#directory-leave-name" title="general">directory-leave-name</a> dir))
           (<span class="local-name-binding">par-dir</span> (<a class="applied-name" href="general-1.html#parent-directory" title="general">parent-directory</a> dir)))
       (<a class="applied-name" href="general-1.html#path-list-to-relative-path" title="general">path-list-to-relative-path</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> (<a class="applied-name" href="general-1.html#inverse-return-path-1" title="general">inverse-return-path-1</a> path-list leave-of-dir par-dir))))))

<a name="inverse-return-path-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(inverse-return-path-1 path-list leave-dir par-dir)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> path-list) '())
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX200" title="R5RS Scheme form">equal?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> path-list) "..") (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> leave-dir (<a class="applied-name" href="general-1.html#inverse-return-path-1" title="general">inverse-return-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list) (<a class="applied-name" href="general-1.html#directory-leave-name" title="general">directory-leave-name</a> par-dir) (<a class="applied-name" href="general-1.html#parent-directory" title="general">parent-directory</a> par-dir))))
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> ".." (<a class="applied-name" href="general-1.html#inverse-return-path-1" title="general">inverse-return-path-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> path-list) (<a class="applied-name" href="general-1.html#directory-leave-name" title="general">directory-leave-name</a> par-dir) (<a class="applied-name" href="general-1.html#parent-directory" title="general">parent-directory</a> par-dir))))))


<div class="schemedoc-section-comment">;;; Other functions. 
;;; Here follows a set of miscellaneous functions.</div>

<a name="re-break"></a><div class="schemedoc-definition-comment">;; A quite special HTML line breaking function.
;; Html format str, either with br og p tags between lines.
;; depends on break-at-all from decoding stuff. 
;; Should perhaps be in the convenience library???</div><a name="re-break"></a><span><a href="../general.html#re-break"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(re-break str)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">line-breaker</span> (break-at-all #\newline)))  <span class="comment">; from decoding stuff</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">lines</span> (line-breaker str))
         (<span class="local-name-binding">line-lengths</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> lines))
         (<span class="local-name-binding">max-line-length</span> (<a class="applied-name" href="general-1.html#max-int-list" title="general">max-int-list</a> line-lengths)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> max-line-length 120)
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> 
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">ln</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> ln "&lt;p&gt;")) lines))
       (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX411" title="R5RS Scheme form">apply</a> <a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> 
          (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX412" title="R5RS Scheme form">map</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">ln</span>) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> ln "&lt;br&gt;")) lines))))))

<a name="max-int-list"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(max-int-list lst)</span>
 (<a class="applied-name" href="general-1.html#max-int-list-help" title="general">max-int-list-help</a> lst 0))
 
<a name="max-int-list-help"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(max-int-list-help lst res)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> lst) 
      res
      (<a class="applied-name" href="general-1.html#max-int-list-help" title="general">max-int-list-help</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> lst) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX247" title="R5RS Scheme form">max</a> res (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> lst)))))


<a name="CR"></a><div class="schemedoc-definition-comment">;; Return a CR string</div><a name="CR"></a><span><a href="../general.html#CR"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">CR</span> (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> #\newline))

<a name="newline-string"></a><div class="schemedoc-definition-comment">;; Return a CR string.
;; Please notice that there is a conflict between this function and the MzScheme url.ss net stuff.
;; (We should get rid of this function in LAML).</div><a name="newline-string"></a><span><a href="../general.html#newline-string"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(newline-string)</span>
  (<a class="applied-name" href="general-1.html#as-string" title="general">as-string</a> #\newline))


<span class="comment">; Functions earlier in the cgi library</span><br />
<a name="save-a-list"></a><div class="schemedoc-definition-comment">;; Save the alist on a file named filename. Filename is assumed to be a full path to the file.</div><a name="save-a-list"></a><span><a href="../general.html#save-a-list"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(save-a-list alist filename)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (file-exists? filename)   <span class="comment">; new 31.3.2000</span><br />       (delete-file filename))
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX443" title="R5RS Scheme form">with-output-to-file</a> filename
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> () (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX459" title="R5RS Scheme form">write</a> alist))))

<a name="unique-timed-file-name"></a><div class="schemedoc-definition-comment">;; Return a unique file name with prefix. The suffic becomes the current-time i seconds representation</div><a name="unique-timed-file-name"></a><span><a href="../general.html#unique-timed-file-name"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(unique-timed-file-name prefix)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> prefix (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX292" title="R5RS Scheme form">number-&gt;string</a> (current-time))))

<a name="file-append"></a><div class="schemedoc-definition-comment">;; Append x to file-name. The file is assumed to contain a Lisp list. x is added (actually pre-pended) to the list on the file,
;; and the file is written back. The ordering of the elements in the file list is not assumed to be important.
;; As a precondition, the file named file-name is assumed to exists.</div><a name="file-append"></a><span><a href="../general.html#file-append"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-append file-name x)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">port</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
        (<span class="local-name-binding">contents</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX449" title="R5RS Scheme form">read</a> port))
        (<span class="local-name-binding">new-contents</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX334" title="R5RS Scheme form">append</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> x) contents)))
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> port)
  (delete-file file-name)  <span class="comment">; new!</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">output-port</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX445" title="R5RS Scheme form">open-output-file</a> file-name)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX459" title="R5RS Scheme form">write</a> new-contents output-port)
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX447" title="R5RS Scheme form">close-output-port</a> output-port))))

<a name="file-read"></a><div class="schemedoc-definition-comment">;; Read the first Lisp expression from file-name.
;; With an optional second parameter, read form number n from file.
;; .form (file-read file-name [n])
;; .pre-condition Assume that there are at least n forms on file</div><a name="file-read"></a><span><a href="../general.html#file-read"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-read file-name . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">n</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list 1))
       (<span class="local-name-binding">port</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
      )
   <span class="comment">; read n-1 forms</span><br />   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX413" title="R5RS Scheme form">for-each</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">n</span>)  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX449" title="R5RS Scheme form">read</a> port)) (<a class="applied-name" href="general-1.html#number-interval" title="general">number-interval</a> 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))

   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">contents</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX449" title="R5RS Scheme form">read</a> port)))
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> port)
     contents)))

<a name="file-read-all"></a><div class="schemedoc-definition-comment">;; Read all Lisp expression from file-name.
;; This function returns these forms as a list of top level forms from the file.</div><a name="file-read-all"></a><span><a href="../general.html#file-read-all"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-read-all file-name)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">port</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
        (<span class="local-name-binding">contents</span> (<a class="applied-name" href="general-1.html#file-read-all-1" title="general">file-read-all-1</a> port '())))
   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> port)
   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX335" title="R5RS Scheme form">reverse</a> contents)))

<a name="file-read-all-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-read-all-1 port res)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">form</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX449" title="R5RS Scheme form">read</a> port)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> form)
       res
       (<a class="applied-name" href="general-1.html#file-read-all-1" title="general">file-read-all-1</a> port (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> form res)))))

<a name="file-write"></a><div class="schemedoc-definition-comment">;; Write the list expression x to the file named file-name. 
;; The writing is done using the Scheme write function.
;; .parameter x An arbitrary value that can be written with write.
;; .parameter filename The name of the file (a string).</div><a name="file-write"></a><span><a href="../general.html#file-write"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(file-write x file-name)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (file-exists? file-name) (delete-file file-name))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">output-port</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX445" title="R5RS Scheme form">open-output-file</a> file-name)))
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX459" title="R5RS Scheme form">write</a> x output-port)
    (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX447" title="R5RS Scheme form">close-output-port</a> output-port)))

<a name="save-on-file"></a><div class="schemedoc-definition-comment">;; Displays the first parameter x on a file named filename.
;; This is a minor convenience function, and an alternative to using the standard Scheme output functions.
;; .parameter x The string to be written.
;; .parameter filename The name of the file (a string).</div><a name="save-on-file"></a><span><a href="../general.html#save-on-file"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(save-on-file x filename)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (file-exists? filename) 
       (delete-file filename))
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX443" title="R5RS Scheme form">with-output-to-file</a> filename
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> () (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX461" title="R5RS Scheme form">display</a> x))))


<a name="id-1"></a><div class="schemedoc-definition-comment">;; The identify function of one parameter</div><a name="id-1"></a><span><a href="../general.html#id-1"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(id-1 x)</span> x)




<a name="multiplum-of"></a><div class="schemedoc-definition-comment">;; Is a (the first par) a multiplum of b (the last par)?</div><a name="multiplum-of"></a><span><a href="../general.html#multiplum-of"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(multiplum-of a b)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX259" title="R5RS Scheme form">remainder</a> a b)))



<a name="copy-text-file"></a><div class="schemedoc-definition-comment">;; Copy the text file in from-path to the file in to-path. 
;; A quick and dirty solution by reading and writing strings to and from files.
;; If the destination file exists you must pass a third parameter, overwrite, with the value #t</div><a name="copy-text-file"></a><span><a href="../general.html#copy-text-file"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(copy-text-file from-path to-path overwrite?)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (file-exists? to-path) overwrite?) (delete-file to-path))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">contents</span> (<a class="schemedoc-name" href="../../../lib/man/file-read.html#read-text-file" title="Manual: file-read">read-text-file</a> from-path)))
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (file-exists? to-path))
        (<a class="schemedoc-name" href="../../../lib/man/file-read.html#write-text-file" title="Manual: file-read">write-text-file</a> contents to-path)
        (error (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "copy-a-file: Overwriting an existing file requires a third overwrite #t parameter: " to-path)))))


<a name="copy-files"></a><div class="schemedoc-definition-comment">;; Copy each of the files in the list files from source-dir to target-dir.
;; Both source-dir and target-dir ends in a slash.
;; If the optional boolean parameter warn-if-non-existing-source is #t a non-fatal warning is issued
;; if the source file does not exist. If the boolean parameter is #f, a fatal error will occur.
;; .form (copy-files files source-dir target-dir [warn-if-non-existing-source])
;; .parameter files A list of file names (without initial path).
;; .parameter source-dir The source directory in which the files are supposed to exist.
;; .parameter target-dir An existing directory to which the files are copied.
;; .parameter warn-if-non-existing-source A boolean parameter that controls the error reaction. Defaults to #f.</div><a name="copy-files"></a><span><a href="../general.html#copy-files"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(copy-files files source-dir target-dir . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">warn-if-non-existing-source</span> (<a class="applied-name" href="general-1.html#optional-parameter" title="general">optional-parameter</a> 1 optional-parameter-list #f)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX123" title="R5RS Scheme form">letrec</a> ((<span class="local-name-binding">copy-a-file</span> 
            (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">f</span>)
             (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">target-file</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> target-dir f))
                   (<span class="local-name-binding">source-file</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> source-dir f))
                  )
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (file-exists? target-file) (file-exists? source-file)) (delete-file target-file))
               (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((file-exists? source-file) (copy-file source-file target-file))
                     (warn-if-non-existing-source (<a class="applied-name" href="general-1.html#display-warning" title="general">display-warning</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Could not copy the file " source-file)))
                     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "copy-file: Source does not exist:" source-file)))))))
   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX413" title="R5RS Scheme form">for-each</a> copy-a-file files))))


<a name="min-max-limited"></a><div class="schemedoc-definition-comment">;; Ensure that the number x is in between min and max, or that min or max is returned.
;; More specifically, if x is not between min and max, the closest of min and max is returned.
;; .pre-condition min &lt;= max</div><a name="min-max-limited"></a><span><a href="../general.html#min-max-limited"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(min-max-limited x min max)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> x min) min)
        ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> min x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX238" title="R5RS Scheme form">&lt;=</a> x max)) x)
        ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> x max) max)
        (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="applied-name" href="general-1.html#laml-error" title="general">laml-error</a> "min-max-limited: Should not happen!" x min max))))
    
</pre></font><div>&nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p></div></body></html>